[英]java.lang.NoClassDefFoundError jar application
I got a maven project with Netbeans 8 (linux). 我有一个使用Netbeans 8(Linux)的Maven项目。
My project is a maven application that I have to 'export' as a JAR runnable JAVA application. 我的项目是一个Maven应用程序,必须将其“导出”为JAR可运行的JAVA应用程序。 While I'm developing the system in Netbeans everything works fine with maven dependencies, but after compile and generate the .jar file in the target folder I got the error NoClassDefFoundError. 当我在Netbeans中开发系统时,一切都可以与Maven依赖项一起正常工作,但是在目标文件夹中编译并生成.jar文件后,出现错误NoClassDefFoundError。 In my searches through google I found that this problem is caused when I have the dependencies in development environment but not when it's compiled with classpath. 在我通过google进行的搜索中,我发现此问题是由于我在开发环境中具有依赖项而不是使用classpath进行编译而引起的。
One solution is to include dependencies jar as library in project, but with this I lost maven functionality. 一种解决方案是将依赖项jar作为库包含在项目中,但与此同时,我失去了Maven功能。 I don't wanna make it, just in last case. 我不想这样做,只是在最后一种情况下。
How can I solve this problem without add dependencies as library inside project? 如何在不添加依赖项作为项目内部库的情况下解决此问题?
Thank you very much! 非常感谢你!
You do not use the correct maven plugin to generate a runnable JAR, meaning a jar with all dependencies within it. 您没有使用正确的maven插件来生成可运行的JAR,这意味着其中包含所有依赖项的jar。 Here is how it should look like 这是它的样子
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>.....</finalName>
<outputDirectory>${basedir}</outputDirectory>
<archive>
<manifest>
<mainClass>......</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
What you have configured is the standard maven plugin to generate a jar file, but without the dependencies included. 您配置的是用于生成jar文件的标准maven插件,但不包括依赖项。
What is generating error is the Hibernate and the POI. 产生错误的是休眠和POI。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.print.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>"mvn deploy:deploy-file -Durl=file:///var/www/projetos/041print-proc/lib/ -Dfile=hibernate-core-4.3.10.Final.jar -DgroupId=org.hibernate -DartifactId=hibernate-core -Dpackaging=jar -Dversion=4.3.10.Final"</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.10.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<name>041 Print Processadores</name>
<description>Processadores de Texto para Dados Variáveis</description>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.