gpt4 book ai didi

java - 将主项目jar添加到项目根文件夹中

转载 作者:行者123 更新时间:2023-12-01 10:51:56 24 4
gpt4 key购买 nike

Apache Maven 3.3.3
OS name: "windows 7"

我的 mvn 项目中有主类:

src/main/java/rev/App.java

App.java是默认的maven main “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>

程序集.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>

关于java - 将主项目jar添加到项目根文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33818477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com