我有一个小的实用程序,用Java编写,用Netbeans作为" Maven项目" (项目上的小图标有风格化的" m"在它上面)。我想打包这个实用程序,以及它所依赖的库,作为一个jar文件;我希望jar文件包含必要的运行时库,所以我不必单独打包它们。
Netbeans的指示说,当我进行构建时,我将会遇到错误的问题。和' lib'在项目目录下创建的目录,以及(因为我已经在项目属性中设置了主类),我将在我的清单文件中指定它。这些都没有发生过;该项目在IDE下构建并运行良好,但它创建的jar只包含实用程序特定的类,没有库类,清单没有写入我的主类,库类不在jar中
是因为这是一个maven项目而不是默认的Netbeans Java项目吗?如何在Netbeans中使用Maven项目完成这项工作?
-
按照建议添加maven-assembly-plugin后,控制台输出来自"清理和构建"看起来像这样:
cd C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.7.0_07" M2_HOME=C:\\devTools\\apache-maven cmd /c "\"\"C:\\devTools\\apache-maven\\bin\\mvn.bat\" -DskipTests=true
-Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.1\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install\"" Scanning for projects...
------------------------------------------------------------------------ Building OlbUserLoad 1.0-SNAPSHOT
------------------------------------------------------------------------
--- maven-clean-plugin:2.4.1:clean (default-clean) @ OlbUserLoad --- Deleting C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target
--- maven-resources-plugin:2.5:resources (default-resources) @ OlbUserLoad --- [debug] execute contextualize Using 'UTF-8' encoding to copy filtered resources. Copying 1 resource Copying 0 resource
--- maven-compiler-plugin:2.0.2:compile (default-compile) @ OlbUserLoad --- Compiling 1 source file to C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target\classes
--- maven-resources-plugin:2.5:testResources (default-testResources) @ OlbUserLoad --- [debug] execute contextualize Using 'UTF-8' encoding to copy filtered resources. skip non existing resourceDirectory C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\src\test\resources
--- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ OlbUserLoad --- Nothing to compile - all classes are up to date
--- maven-surefire-plugin:2.10:test (default-test) @ OlbUserLoad --- Tests are skipped.
--- maven-jar-plugin:2.3.2:jar (default-jar) @ OlbUserLoad --- Building jar: C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target\OlbUserLoad-1.0-SNAPSHOT.jar
--- maven-install-plugin:2.3.1:install (default-install) @ OlbUserLoad --- Installing C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target\OlbUserLoad-1.0-SNAPSHOT.jar to C:\Users\rcook\.m2\repository\com\accesspoint\OlbUserLoad\1.0-SNAPSHOT\OlbUserLoad-1.0-SNAPSHOT.jar Installing C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\pom.xml to C:\Users\rcook\.m2\repository\com\accesspoint\OlbUserLoad\1.0-SNAPSHOT\OlbUserLoad-1.0-SNAPSHOT.pom
------------------------------------------------------------------------ BUILD SUCCESS
------------------------------------------------------------------------ Total time: 2.155s Finished at: Fri Apr 22 10:15:28 EDT 2016 Final Memory: 17M/152M
------------------------------------------------------------------------
我希望这有助于我们弄清楚还缺少什么。
答案 0 :(得分:3)
在.pom文件中包含此插件。这是为了告诉Maven使用依赖项来组装应用程序。
在此之后,在Netbeans中构建项目,您将看到带有依赖项的jar。
If Worksheets.Count = 18 Then
Worksheets.Delete(Worksheets.Count)
End If
答案 1 :(得分:0)
要从Netbeans项目中创建Maven jar
文件,您需要:
cd
命令)mvn clean package
。 jar
将在<project dir>/target
中。了解有关使用Maven创建Jar文件的更多信息:https://javatutorial.net/create-java-jar-file-with-maven