问题
I have a project with the following pom.xml and I have removed some of the unwanted stuff from it. What I intended to happen was to generate a jar file and ultimately generate a war
package that includes the jar
file as a library. Unfortunately, this doesn't seem to be happening with the following 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>
<artifactId>test</artifactId>
<groupId>com.test.abcd</groupId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test Application</name>
....
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>target/www/</warSourceDirectory>
</configuration>
<executions>
<execution>
<id>build-war-in-classes</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</project>
Even though this generates both a jar
and a war
during the package phase, the war
doesn't include jar
file (WEB-INF/lib/test-0.0.1-SNAPSHOT.jar
) as a library and in stead I see the following classes,
META-INF/
META-INF/MANIFEST.MF
....
WEB-INF/
WEB-INF/classes/
....
What could be causing this behaviour ?
回答1:
I think you're missing a conf flag in war plugin configuration:
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
Quote from https://maven.apache.org/plugins/maven-war-plugin/faq.html
How do I create a JAR containing the classes in my webapp?
If you would simply like to package the classes and resources as a JAR in WEB-INF/lib rather than as loose files under WEB-INF/classes, use the following configuration:
<plugin> <artifactId>maven-war-plugin</artifactId> <version>3.1.0</version> <configuration> <archiveClasses>true</archiveClasses> </configuration> </plugin>
来源:https://stackoverflow.com/questions/43972148/maven-project-build-into-jar-and-war