如果包类型是POM,则创建JAR文件

时间:2016-05-04 06:19:57

标签: java spring-boot maven-2 maven-plugin maven-shade-plugin

如果项目包装类型为" POM",如何制作JAR文件?原因是我在这个项目中添加了几个子模块。我使用着色插件制作一个JAR文件,但看起来没有在.m2目录中创建,但它创建的目标文件夹中没有任何类,资源等

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>HealthProject</groupId>
  <artifactId>HealthProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <excludes>
                  <exclude>classworlds:classworlds</exclude>
                  <exclude>junit:junit</exclude>
                  <exclude>jmock:*</exclude>
                  <exclude>*:xml-apis</exclude>
                  <exclude>org.apache.maven:lib:tests</exclude>
                  <exclude>log4j:log4j:jar:</exclude>
                </excludes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
    <modules>
        <module>database</module>
         <module>services</module>
    </modules>
</project> 

1 个答案:

答案 0 :(得分:1)

我会看到以下解决方案。

您将{1}}所依赖的模块添加到other project

<dependency>
    <groupId>HealthProject</groupId>
    <artifactId>database</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>HealthProject</groupId>
    <artifactId>services</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

您在HealthProject创建了一个新模块,该模块将创建一个HealthProject的Jar。

<parent>
    <groupId>HealthProject</groupId>
    <artifactId>HealthProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>healthproject-all</artifactId>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>HealthProject</groupId>
        <artifactId>database</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>HealthProject</groupId>
        <artifactId>services</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

然后在other project中将其添加为依赖项。

<dependencies>
    <dependency>
        <groupId>HealthProject</groupId>
        <artifactId>healthproject-all</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>pom</type>
    </dependency>
</dependencies>