I am currently building a little Apache-Mina Server app. I am using Maven to build it. When i try to run the jar, I get the following error:

我目前正在构建一个Apache-Mina Server应用程序。我正在使用Maven来构建它。当我尝试运行jar时,我收到以下错误:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/mina/filter/codec/ProtocolCodecFactory 
Caused by: java.lang.ClassNotFoundException: org.apache.mina.filter.codec.Protoc  olCodecFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: de.fr1zle.gpsserver.GpsServer. Program will exit.

Running in eclipse is not a problem.

在日食中运行不是问题。

This is what the generated MANIFEST looks like:

这就是生成的MANIFEST的样子:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: fr1zle
Build-Jdk: 1.6.0_23
Main-Class: de.fr1zle.gpsserver.GpsServer
Class-Path: commons-lang-2.1.jar plexus-utils-1.1.jar junit-4.8.2.jar 
 log4j-1.2.14.jar slf4j-jdk14-1.5.11.jar slf4j-api-1.5.11.jar antlr-2.
 7.6.jar commons-collections-3.1.jar dom4j-1.6.1.jar hibernate-commons
 -annotations-3.2.0.Final.jar hibernate-jpa-2.0-api-1.0.0.Final.jar jt
 a-1.1.jar hibernate-annotations-3.5.6-Final.jar hibernate-core-3.5.6-
 Final.jar mysql-connector-java-5.1.15.jar mina-core-2.0.3.jar

And this is (part of) my pom.xml:

这是我的pom.xml(的一部分):

<groupId>de.fr1zle.gpsserver</groupId>
    <artifactId>GPSServer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>GPSServer</name>
    <packaging>jar</packaging>
    <description>Tracks location of GPS modules and the information they submit.</description>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>de.fr1zle.gpsserver.GpsServer</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

What am I doing wrong here?

我在这做错了什么?

2 个解决方案

#1


7

When you run from Eclipse, Eclipse configures the class path for you. Therefore, you don't run into this issue.

从Eclipse运行时,Eclipse会为您配置类路径。因此,您不会遇到此问题。

When you are running outside of Eclipse, you need to set up the CLASSPATH either by providing the path to these jar files ie file:/dev/libs/mina-core-2.0.3.jar in the MANIFEST.MF or by adding the -cp option when executing the app. Don't forget that the entries in the class-path in the manifest file are either relative to the JAR in which they are embedded or absolute path to a local file directory.

当您在Eclipse之外运行时,您需要通过提供这些jar文件的路径来设置CLASSPATH,即文件:MANIFEST.MF中的文件:/dev/libs/mina-core-2.0.3.jar或者添加执行应用程序时的-cp选项。不要忘记清单文件中类路径中的条目要么是相对于嵌入它们的JAR,要么是本地文件目录的绝对路径。

Your other option is to package it as one jar using the maven assembly plugin jar-with-dependencies.

您的另一个选择是使用maven程序集插件jar-with-dependencies将其打包为一个jar。

更多相关文章

  1. java基础IO删除文件夹文件
  2. java动态加载jar文件
  3. IT兄弟连 JavaWeb教程 文件上传技术
  4. JAVA 实现tail -f 日志文件监控功能
  5. 蓝桥杯--第七届决赛:路径之谜
  6. 读取Excel文件并跳过空行但不是空列

随机推荐

  1. Android简明开发教程二十二:使用资源Resou
  2. Android之不要滥用SharedPreferences
  3. 解决Android sdk更新不能下载或下载内容
  4. Android layout常见的属性大全
  5. 老罗Android开发视频教程 (android常用布
  6. 让Python在Android系统上飞一会儿
  7. Androidの自定义Spinner实现
  8. 【Android Studio使用教程4】Android Stu
  9. 修改android升级系统后启动系统,提示andro
  10. Android TextView 设置行间距字间距