使用解压缩的JAR依赖项构建WAR项目?

Rom*_*las 11 build-process maven-2

我有两个项目,my-libmy-webapp.第一个项目是依赖my-webapp.因此,当要求Maven2构建我的WAR时,my-libJAR将添加WEB-INF/lib/到Web应用程序的目录中.

但是,我希望将my-libJAR直接解压缩到WEB-INF/classes目录中,就像my-lib源代码包含在项目中一样my-webapp.

换句话说,而不是具有以下WAR内容:

my-webapp/
  ...
  WEB-INF/
    lib/
      my-lib-1.0.jar
      ... (others third libraries)
Run Code Online (Sandbox Code Playgroud)

我想拥有:

my-webapp/
  ...
  WEB-INF/
    classes/
      my-lib files
    lib/
      ... (others third libraries)
Run Code Online (Sandbox Code Playgroud)

有没有办法配置my-webapp或Maven2战争插件来实现这一目标?

Ric*_*ler 6

正如blaufish的回答所说,你可以使用maven-dependency-plugin的unpack 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>
Run Code Online (Sandbox Code Playgroud)


小智 1

解压魔力似乎很接近您的目标。但不确定如何完成您提议的整个流程。

(顺便说一句,我怀疑这是否是一个好主意。实用程序类应该放入 jar 中,并且这些 jar 要么放在 WAR 中,要么放在 EAR 中。解压实用程序 jar 似乎是错误的)