How do I create a Netbeans style Jar with all depe

2019-02-13 15:54发布

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

  • All the dependencies in a separate lib folder
  • The main project jar with a manifest that includes the lib folder on it's classpath

1条回答
何必那么认真
2楼-- · 2019-02-13 16:29

In your pom.xml file ...

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) 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>
查看更多
登录 后发表回答