繁体   English   中英

在Webapp文件夹中复制jar文件Maven项目

[英]Copying jar files maven project in webapp folder

我试图将几个jar文件从web-inf / lib文件夹复制到src / main / webapp / applet文件夹,这些都是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>

注意:在这两个试验中,我都发现在更新项目时在webapp内创建了applet文件夹,但在构建过程中未修改/创建该文件夹。

任何建议将不胜感激。请不要将其标记为重复,我所寻找的每份参考资料都有助于将如何从源复制到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>

检查以下ant任务是否对您有用?

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>move-applet-jar-files</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target name="Copying jar files for applets">
                            <echo message="your jar file to be copied" />
                            <copy file="${source.dir}/abc.jar" tofile="${target.dir}/abc.jar" />
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM