【问题标题】:Maven plugin to create Java executable用于创建 Java 可执行文件的 Maven 插件
【发布时间】:2014-06-27 19:29:07
【问题描述】:

我正在尝试创建一个包含我的所有类和依赖 JAR 的可执行 jar。我尝试了多个maven插件,但没有成功。 “jar-with-dependencies”选项之一添加了所有依赖项,但依赖的 JAR 被分解。

我想要的是

<MyMain>
   <META-INF>
       MANIFEST.MF //containing MAIN class and Classpath with all the dependencies.
   <com>
   <lib> 
        spring-core-3.0.jar
        spring-beans-3.0.jar 
        // and all dependent jars underneath

我尝试了以下方法,但无济于事。它会创建一个适当的清单,但不会复制所有的罐子。

    <pluginManagement>
        <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>MyMainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>


        </plugins>
    </pluginManagement>

我使用 Spring Tool Suite 并运行->maven install

【问题讨论】:

    标签: package maven-plugin executable-jar


    【解决方案1】:

    你可以使用组装插件:

    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
         <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
      </configuration>
     </plugin>
    

    【讨论】:

    • 谢谢。我相信我也使用了程序集插件,但是它爆炸了我的依赖 JAR,而不是把它们复制到 lib 文件夹中。
    • 爆炸是什么意思?
    • 提取所有文件并在我的主 JAR 中创建文件夹/文件结构。
    • 更新了我原来的帖子。我使用 Spring Tool Suite 并运行->maven install
    • 你能添加一张结构外观的图片吗?我想了解爆炸是什么意思。
    猜你喜欢
    • 2012-06-13
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多