java 如何在 lib 文件夹中创建具有所有依赖项的 Netbeans 样式 Jar?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17654213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I create a Netbeans style Jar with all dependencies in a lib folder?
提问by The Coordinator
As the question says, how to package a Netbeans Maven project exactly the way a Netbeans native project is packaged:
正如问题所说,如何完全按照打包 Netbeans 本机项目的方式打包 Netbeans Maven 项目:
- All the dependencies in a separate lib folder
- The main project jar with a manifest that includes the lib folder on it's classpath
- 单独的 lib 文件夹中的所有依赖项
- 带有清单的主项目 jar,其中包含类路径上的 lib 文件夹
回答by The Coordinator
In your pom.xml file ...
在您的 pom.xml 文件中...
1) Add this code to your project->properties node. This will define your main class in a central place for use in many plugins.
1) 将此代码添加到您的项目-> 属性节点。这将在一个中心位置定义您的主类,以便在许多插件中使用。
<properties>
<mainClass>project.Main.class</mainClass>
</properties>
2) Add this code to your project->build->plugins node. It will collect all your jar dependencies into a lib folder AND compile your main class jar with the proper classpath reference:
2)将此代码添加到您的项目->构建->插件节点。它会将所有 jar 依赖项收集到一个 lib 文件夹中,并使用正确的类路径引用编译主类 jar:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>