java - 将jar文件复制到webapp文件夹中的maven项目中

标签 java eclipse maven jboss applet

我正在尝试将一些 jar 文件从 web-inf/lib 文件夹复制到 src/main/webapp/applet 文件夹,这些都是必需的 小程序的存档,以便 jar 文件出现在输出 war 文件中。

我希望这个复制操作需要在maven构建期间执行。我已经尝试了两个选项,其中一个是

ma​​ven-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

下一次尝试是使用下面的ma​​ven-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/

相关文章:

java - Spark 因 org.apache.kafka.common.serialization.StringDeserializer 失败并出现 NoClassDefFoundError

java - BIGINT UNSIGNED 自动增量被 mybatis 破坏

java - 方法不在 for (if-else) 循环中执行,并返回原始对象

java - 如何在android中将数据库中的数据显示为复选框列表

java - 应用程序启动时崩溃

java - ViewPart 中的 onShow 和 onHide 监听器 - Java Eclipse RCP

java - Maven 远程资源插件未创建 remote-resources.xml list 文件

linux - 将我自己的 Git 服务器与我的 Windows Eclipse IDE 链接起来

maven - JMockit 版本 1.17 显示错误 NoClassDefFoundError : org. junit.runner.Runner?

java - 找不到符号符号: class NestableRuntimeException location: package org. hibernate.exception