Fab*_*der 5 java netbeans build executable-jar maven
首先:我是maven的新手.我制作了我的第一个maven应用程序并在IDE中成功测试了它.构建总是成功的,一切都像魅力一样.
现在我想将项目导出为内置依赖项的可执行jar,但我不确定它为什么不起作用.
我将以下内容添加到我的pom文件中,因为这是我在类似问题的各种答案中找到的
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.pwc.scfa.pensareautomatio3.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我知道这指定了JVM启动的主类,因为IDE没有自动设置它.
我将jar放在目标目录中,将其复制到另一个目录并尝试执行它.
遗憾的是,引发了以下错误:
能否请你给我一个提示,我可能出错了?那太好了.(我正在使用NetBeans,如果有任何帮助的话.)
这是我的StackTrace:
C:\Users\scfa\Desktop>java -jar PensareAutomatio-1.1.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/openxm
l4j/exceptions/InvalidFormatException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.openxml4j.exceptions
.InvalidFormatException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Run Code Online (Sandbox Code Playgroud)
谢谢 :)
如果我是正确的,那么maven-jar-plugin将使用所有已编译的.class文件创建一个jar,但不包含依赖项。
我建议使用maven-assembly-plugin并将其绑定到程序包执行阶段,这样在运行mvn install时就可以构建它
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.pwc.scfa.pensareautomatio3.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参见此答案。
| 归档时间: |
|
| 查看次数: |
5168 次 |
| 最近记录: |