构建具有未压缩JAR依赖关系的WAR项目? [英] Building a WAR project with unzipped JAR dependency?
问题描述
我有两个项目,my-lib
和my-webapp
.第一个项目是my-webapp
的依赖项.因此,当要求Maven2构建我的WAR时,会将my-lib
JAR添加到Web应用程序的WEB-INF/lib/
目录中.
I have two projects, my-lib
and my-webapp
. The first project is a dependency of my-webapp
. Thus, when ask Maven2 to build my WAR, the my-lib
JAR is added in the WEB-INF/lib/
directory of the web application.
但是,我想直接在WEB-INF/classes
目录中解压缩my-lib
JAR,就像my-lib
源包含在项目my-webapp
中一样.
However, I want to have the my-lib
JAR unzipped directly in the WEB-INF/classes
directory, exactly as if the my-lib
sources were contained in the project my-webapp
.
换句话说,不是具有以下WAR内容:
In others words, instead of having the following WAR content:
my-webapp/
...
WEB-INF/
lib/
my-lib-1.0.jar
... (others third libraries)
我想要那个:
my-webapp/
...
WEB-INF/
classes/
my-lib files
lib/
... (others third libraries)
是否可以通过配置my-webapp
或Maven2 war插件来实现这一目标?
Is there a way to configure the my-webapp
or the Maven2 war plugin to achieve that?
推荐答案
正如blaufish的回答所说,您可以使用maven-dependency-plugin的解压缩特定工件.
As blaufish's answer says, you can use the maven-dependency-plugin's unpack mojo to unpack an artifact. However to avoid the jar appearing in WEB-INF/lib, you need to not specify it as a dependency, and instead configure the plugin to unpack specific artifacts.
以下配置将在process-resources阶段将some.group.id:my-lib:1.0:jar的内容解压缩到target/classs中,即使未将工件定义为依赖项也是如此.尽管这样做有可能破坏您的实际内容,但请务必小心,这可能会导致大量调试.
The following configuration will unpack the contents of some.group.id:my-lib:1.0:jar into target/classes during the process-resources phase, even if the artifact is not defined as a dependency. Be careful when doing this though as there is potential to clobber your actual content, this can cause much debugging.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-my-lib</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>some.group.id</groupId>
<artifactId>my-lib</artifactId>
<version>1.0</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
这篇关于构建具有未压缩JAR依赖关系的WAR项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!