要在项目根文件夹中添加主项目jar

时间:2015-11-20 03:29:12

标签: java xml maven

Apache Maven 3.3.3
OS name: "windows 7"

我的mvn项目中有一个主要类:

src/main/java/rev/App.java

App.java是默认的maven主"Hello World!"

然后我将依赖项放在根目录中的lib文件夹中( assembly.xml下面的):

.....

但是,执行此操作后,项目的主jar不会出现在文件夹中的任何位置。如何让主jar出现在lib文件夹的根文件夹中?

的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>rev</groupId>
  <artifactId>rev</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>rev</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
          <configuration>
            <descriptors>
              <descriptor>src/main/assembly/assembly.xml</descriptor>
            </descriptors>
          </configuration>
          <executions>
            <execution>
              <id>make-assembly</id> <!-- this is used for inheritance merges -->
              <phase>package</phase> <!-- append to the packaging phase. -->
              <goals>
                <goal>single</goal> <!-- goals == mojos -->
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.4</version>
    </dependency>
  </dependencies>

</project>

assembly.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
  <id>bin</id>
  <baseDirectory>/</baseDirectory>

  <formats>
    <format>zip</format>
  </formats>

  <includeBaseDirectory>false</includeBaseDirectory>

  <files>
    <file>
      <source>${project.basedir}/src/main/config/config.properties</source>
      <filtered>true</filtered>
    </file>
  </files>

  <fileSets>
    <fileSet>
      <directory>${project.basedir}/src/main/scripts</directory>
      <outputDirectory>scripts</outputDirectory>
    </fileSet>
  </fileSets>

  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>

    <dependencySet>
      <useProjectArtifact>false</useProjectArtifact>
      <useTransitiveDependencies>false</useTransitiveDependencies>
      <unpack>false</unpack>
      <includes>
        <include>*:*:jar</include>
      </includes>
    </dependencySet>
  </dependencySets>
</assembly>

1 个答案:

答案 0 :(得分:1)

您需要在程序集配置中显式添加构建的项目jar。

<files>
    <file>
       <source>${project.basedir}/target/${project.build.finalName}.jar</source>
       <outputDirectory>/</outputDirectory>
    </file>
</files>