Maven Jar插件:如何添加所有文件

时间:2019-02-08 15:29:11

标签: java maven jar war

我正在尝试使用maven-jar-plugin生成./mvnw clean install的war文件和jar文件。

我的pom.xml包含:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-services-provided</id>
                    <phase>test</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <configuration>
                        <packaging>jar</packaging>
                        <groupId>${project.groupId}</groupId>
                        <version>${project.version}</version>
                        <file>${project.build.directory}\${project.artifactId}-${project.version}.jar</file>
                    </configuration>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

我也尝试过<phase>compile</phase>

正在创建jar文件,但是它很小,甚至不包含应用程序主类。

如何获得与<packaging>jar</packaging>相同的结果?战争档案看起来不错,而且更大。

我确实读过Maven JAR Plugin 3.0.2 Error ..

1 个答案:

答案 0 :(得分:0)

如果您想在war模块中创建代码的单独jar文件,则configuration should look like this

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
          <archiveClasses>true</archiveClasses>
          <attachClasses>true</attachClasses>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>