Java 将依赖jar插入安装程序jar

Java 将依赖jar插入安装程序jar,java,maven-2,jar,Java,Maven 2,Jar,我有一个多模块maven项目和一个安装子项目。安装程序将作为可执行JAR分发。它将设置数据库并将WAR文件解压缩到应用程序服务器。我想用maven来组装这个罐子,就像这样: /META-INF/MANIFEST.MF /com/example/installer/installer.class /com/example/installer/… /server.war 清单将有一个指向安装程序类的主类条目。如何让maven以这种方式构建jar?您可以使用 首先,您需要向pom.xmlplugins

我有一个多模块maven项目和一个安装子项目。安装程序将作为可执行JAR分发。它将设置数据库并将WAR文件解压缩到应用程序服务器。我想用maven来组装这个罐子,就像这样:

/META-INF/MANIFEST.MF
/com/example/installer/installer.class
/com/example/installer/…
/server.war


清单将有一个指向安装程序类的主类条目。如何让maven以这种方式构建jar?

您可以使用

首先,您需要向pom.xmlplugins部分添加一些信息,以使生成的jar可执行:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>com.example.installer.Installer</mainClass>
      </manifest>
    </archive>
  </configuration>
</plugin>

构建实际的安装程序jar。下面是一个例子:

<assembly>
  <id>installer</id>

  <formats>
    <format>jar</format>
  </formats>

  <baseDirectory></baseDirectory>

  <dependencySets>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <includes>
        <!-- this references your installer sub-project -->
        <include>com.example:installer</include>
      </includes>
      <!-- must be unpacked inside the installer jar so it can be executed -->
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <includes>
        <!-- this references your server.war and any other dependencies -->
        <include>com.example:server</include>
      </includes>
      <unpack>false</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>