[英]maven copy a particular dependency jar to a specific directory in the .war file
I am trying out a Simple Java Web Start project based on the Oracle Tutorial. 我正在尝试基于Oracle Tutorial的Simple Java Web Start项目。 I am using maven to package it as a webapp and deploy it to application server. 我正在使用maven将其打包为webapp并将其部署到应用程序服务器。 The full source code is available here 完整的源代码可在此处获得
https://github.com/KiranMohan/dynamic-tree-javaws-sample-project https://github.com/KiranMohan/dynamic-tree-javaws-sample-project
The maven project structure is like maven项目结构就像
parent
|--lib
|--webapp
The webapp module is a maven war module. webapp模块是一个maven war模块。 It is required to package lib.jar at the root of webapp.war. 需要在webapp.war的根目录下打包lib.jar。 NOT under WEB-INF/lib. 不在WEB-INF / lib下。
How to achieve this in maven? 如何在maven中实现这一目标?
I found that the right way to do this is to use the maven-dependency-plugin. 我发现正确的方法是使用maven-dependency-plugin。 Since "lib.jar" is not used in the compile phase of "webapp" module, it is only a package time dependency. 由于“lib.jar”未在“webapp”模块的编译阶段使用,因此它只是一个包时间依赖项。 Using maven-dependency-plugin, I can copy lib.jar to any required directory during the prepare-package phase. 使用maven-dependency-plugin,我可以在准备包阶段将lib.jar复制到任何所需的目录。 The maven-war package would then include the lib.jar in the .war package. 然后,maven-war包将包含.war包中的lib.jar。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ group id ]</groupId>
<artifactId>[artifact id]</artifactId>
<version>[ version ]</version>
<outputDirectory>${project.build.directory}/${project.artifactId}</outputDirectory>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
Update: There is a webstart-maven-plugin that does a better job of packaging javaws applications. 更新:有一个webstart-maven-plugin可以更好地打包javaws应用程序。 See my sample project 看我的示例项目
https://github.com/KiranMohan/dynamic-tree-javaws-sample-project https://github.com/KiranMohan/dynamic-tree-javaws-sample-project
for details 详情
Well how i said in the comments for sake of readability here is a part of the answer: 那么为了便于阅读,我在评论中说的是答案的一部分:
Since Maven will always store the dependencies of a web project under its WEB-INF/lib
folder by default i (i am no Maven expert ...) would try to place my lib.jar
inside the /target
folder of the project before the phase package
is executed. 由于Maven将始终将Web项目的依赖项存储在其WEB-INF/lib
文件夹中,因此默认情况下我(我不是Maven专家......)会尝试将我的lib.jar
放在项目的/target
文件夹中。阶段package
被执行。
NOTE: I havent tried it out so you will have to adjust the paths - expecially the output path so your lib.jar
is placed properly to be packed into the root of the war
(eg if you open your war
there will be a lib.jar
next to folders such as WEB-INF
). 注意:我还没有尝试过,所以你必须调整路径 - 尤其是输出路径,这样你的lib.jar
就可以正确地放入war
的根源(例如,如果你打开你的war
就会有一个lib.jar
文件夹旁边的文件夹,如WEB-INF
)。
<!--
lets assume the root of my project would be under C:/devjba/projectX this equals the maven
variable ${project.basedir}.
from there the output-directory would be located under C:/devjba/projectX/target which equals the
maven variable ${project.build.directory}. This is the location a .war would be placed in after
the build
lets assume the required jar lib.jar is located under C:/devjba/projectX/misc which would equal to
the expression: ${project.basedir}/misc
-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>foo</id>
<!-- may adjust to another phase before package but make sure your plugin is bound to a phase
because otherwise it wont be invoked during build! Now its bound to the first phase of the
default lifecycle for packaging type war -->
<phase>process-resources</phase>
<goals>
<!-- use the copy-resources goal of this plugin - it will copy resources :) -->
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- this points to /target of the current project, you may adjust it to wherever it must be placed to be packed into the root of the war (just try&error) -->
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<!-- this points to a folder /misc under the project root where we expect the lib.jar -->
<directory>${project.basedir}/misc</directory>
<!-- unless you specify what to include anything of the above directory will be included -->
<includes>
<include>lib.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
As i said i have no experience in signing JARs at all but there is a plugin called maven-jarsigner-plugin
which i guess will do the job (i would sign it, then move it, then package the war) with a manual - i recomend you try to configure it according to my "example configuration of the maven-resource-plugin
and post a new question directly containing your two plugin configurations. Dont forget to link to this question in that case. And also leave this question open so someone with a better approach may correct my way). 正如我所说,我根本没有签署JAR的经验,但有一个名为maven-jarsigner-plugin
,我想这将完成工作(我会签名,然后移动它,然后打包战争)用手册 - 我建议您尝试根据我的“ maven-resource-plugin
示例配置”进行配置,并发布一个直接包含您的两个插件配置的新问题。在这种情况下不要忘记链接到这个问题。并且还要打开这个问题,以便有人开启用更好的方法可以纠正我的方式)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.