如何在 lib 文件夹中创建具有所有依赖项的 Netbeans 样式 Jar? [英] How do I create a Netbeans style Jar with all dependencies in a lib folder?

查看:26
本文介绍了如何在 lib 文件夹中创建具有所有依赖项的 Netbeans 样式 Jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如问题所说,如何完全按照打包 Netbeans 本机项目的方式打包 Netbeans Maven 项目:

As the question says, how to package a Netbeans Maven project exactly the way a Netbeans native project is packaged:

  • 所有依赖项都在一个单独的 lib 文件夹中
  • 带有清单的主项目 jar,其中包含类路径上的 lib 文件夹

推荐答案

在你的 pom.xml 文件中...

In your pom.xml file ...

1) 将此代码添加到您的项目->属性节点.这将在一个中心位置定义您的主类,以便在许多插件中使用.

1) Add this code to your project->properties node. This will define your main class in a central place for use in many plugins.

<properties>
        <mainClass>project.Main.class</mainClass>
</properties>

2) 将此代码添加到您的项目->build->plugins 节点.它会将所有 jar 依赖项收集到一个 lib 文件夹中,并使用正确的类路径引用编译主类 jar:

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:

    <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>

这篇关于如何在 lib 文件夹中创建具有所有依赖项的 Netbeans 样式 Jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆