我有两个项目, my-lib
和 my-webapp
。第一个项目是依赖 my-webapp
。因此,当要求Maven2构建我的WAR时, my-lib
JAR被添加到了 WEB-INF/lib/
Web应用程序的目录。
但是,我想拥有 my-lib
JAR直接解压缩了 WEB-INF/classes
目录,就好像 my-lib
来源包含在项目中 my-webapp
。
换句话说,而不是具有以下WAR内容:
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战争插件来实现呢?
正如blaufish的回答所说,你可以使用maven-dependency-plugin 打开mojo 解压工件。但是,为了避免jar出现在WEB-INF / lib中,您需要 不要将其指定为依赖项,而是将插件配置为 解压缩特定的工件。
以下配置将在process-resources阶段将some.group.id:my-lib:1.0:jar的内容解压缩到目标/类中,即使工件未定义为依赖项。这样做时要小心,因为有可能破坏你的实际内容,这可能会导致很多调试。
<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>
正如blaufish的回答所说,你可以使用maven-dependency-plugin 打开mojo 解压工件。但是,为了避免jar出现在WEB-INF / lib中,您需要 不要将其指定为依赖项,而是将插件配置为 解压缩特定的工件。
以下配置将在process-resources阶段将some.group.id:my-lib:1.0:jar的内容解压缩到目标/类中,即使工件未定义为依赖项。这样做时要小心,因为有可能破坏你的实际内容,这可能会导致很多调试。
<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>
您可以配置maven-dependency-plugin来执行此操作,解压缩而不是复制jar 这里。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<destFileName>optional-new-name.jar</destFileName>
<includes>**/*.class,**/*.xml</includes>
<excludes>**/*test.class</excludes>
</artifactItem>
</artifactItems>
<includes>**/*.java</includes>
<excludes>**/*.properties</excludes>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
该 解压 mojo似乎接近你的目标。不知道如何完成你提出的整个流程。
(顺便说一句,我怀疑这是不是一个好主意。实用程序类应该进入jar,并且罐子放在WAR或者EAR中。解包实用程序jar似乎是错误的)
我能够如上所述使用unpack mojo,而且我将依赖项本身标记为 “提供”(范围) 避免重复WEB-INF / lib下的jar内容。
[哎呀,刚才意识到你在使用Maven。我不删除这个答案,因为它可能会拯救一些Ant用户。所以没有必要让我失望...]
我必须提到多少次 Jar
, War
和 Ear
Ant任务是子任务的子任务 压缩 一? :-)如果我没记错的话,这样的事情可以解决问题:
<war dist="my-webapp.war">
<zipgroupfileset dir="libs" includes="*.jar" prefix="WEB-INF/classes"/>
</war>
也值得一试 src="mylib.jar"
但我没有测试过这个选项。