簡體   English   中英

將主項目jar添加到項目根文件夾中

[英]The to add the main project jar in the project root folder

Apache Maven 3.3.3
OS name: "windows 7"

我的mvn項目中有主班:

src/main/java/rev/App.java

App.java是默認的Maven主程序"Hello World!"

然后,我將依賴項放在根目錄( 下面的assembly.xml )的lib文件夾中:

.....

但是,執行此操作后,項目的主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>

您需要在程序集配置中顯式添加構建的項目jar。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM