我正在尝试将一些 jar 文件从 web-inf/lib 文件夹复制到 src/main/webapp/applet 文件夹,这些都是必需的 小程序的存档,以便 jar 文件出现在输出 war 文件中。
我希望这个复制操作需要在maven构建期间执行。我已经尝试了两个选项,其中一个是
maven-war-plugin 如下。
<webResources>
<resource>
<directory>src/main/webapp/WEB-INF/lib</directory>
<filtering>true</filtering>
<includes>
<include>**/*.jar</include>
</includes>
<targetPath>${basedir}/src/main/webapp/applet</targetPath>
</resource>
</webResources>
构建的轨迹如下。
[INFO] --- maven-war-plugin:2.6:war (default-war) @ myapp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [myapp] in [C:\jboss_projects\myapp\src\main\webapp]
[INFO] Processing war project
[INFO] Copying webapp webResources [C:\jboss_projects\myapp\src/main/webapp/WEB-INF/lib] to [C:\jboss_projects\myapp\src\main\webapp]
[INFO] Webapp assembled in [999 msecs]
[INFO] Building war: C:\jboss_projects\myapp\target\myapp.war
下一次尝试是使用下面的maven-resources-plugin。
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/webapp/applet</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>src/main/webapp/WEB-INF/lib</directory>
<filtering>true</filtering>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Note: in both trials I found the applet folder created inside webapp while updating project but during build that folder is not modified/created.
任何建议将不胜感激。请不要将其标记为重复,我查看的每个引用都有助于如何从源复制到 web-inf/lib 文件夹。 不是这个。
最佳答案
wemu 建议有效。这就是它的配置方式,以从本地存储库获取依赖的 jar。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>applet-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.xxx.yyy</groupId>
<artifactId>yyy</artifactId>
<version>1.0</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${basedir}/src/main/webapp/applet</outputDirectory>
<destFileName>yyy.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
关于java - 将jar文件复制到webapp文件夹中的maven项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31160696/