使用maven-assembly-plugin,但jar只包含依赖项目的类,没有app项目类

时间:2014-07-17 15:31:26

标签: maven maven-2 maven-3 maven-plugin maven-assembly-plugin

我有一个库项目,我将其声明为应用项目的<dependency>

库项目的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.my.library</groupId>
    <artifactId>MyLib</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <name>MyLib</name>
    ...

我的应用项目的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.my.app</groupId>
    <artifactId>MyApp</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <name>MyApp</name>

    <dependencies>
      <!--include library project as a dependency-->
      <dependency>
            <groupId>com.my.library</groupId>
            <artifactId>MyLib</artifactId>
            <version>1.0</version>
       </dependency>
      ...
   </dependencies>

因为我需要一个包含我的库项目类的jar,所以我在 App项目的pom.xml中声明了 maven-assembly-plugin :< / p>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
          <descriptor>assembly.xml</descriptor>
    </configuration>
    <executions> 
        <execution> 
            <id>make-jar</id> 
            <phase>package</phase> 
            <goals> 
              <goal>assembly</goal>
            </goals>
        </execution>
     </executions>
</plugin>

assembly.xml 如下所示:

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>jar-with-dependencies</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
            <includes>
                <!--inclucde classes from my library project-->
                <include>com.my.library:MyLib</include>
            </includes>
        </dependencySet>
    </dependencySets>
</assembly>

好的,此时,我在应用程序项目下运行mvn clean install,在target /目录下,我得到了 MyApp-jar-with-dependencies.jar

但是,当我查看上面jar的内容时,包含库项目的类,但不包含我的 App项目的课程?为什么?

0 个答案:

没有答案