如何使用Maven创建目录,然后将JAR文件和依赖项复制到这些目录中。

huangapple go评论62阅读模式
英文:

How to use Maven to create directories then copy jars and dependencies into those directories

问题

我正在将一个Java项目从任何构建过程转换为Maven。

目前,Maven可以编译该项目的JAR文件,但要完全替代Ant,我需要执行两个额外的步骤:

  1. 创建一个文件树
  2. 将项目中存储的编译后的JAR文件和其他文件复制到步骤1中创建的目录中。

这个树需要反映出JAR文件和资源文件将出现在安装在机器上的目录结构。

例如,srs/foo/bar/scripts 目录中的内容可能需要移动到 /usr/local/myFoo/spam/bar/scripts

而JAR文件可能需要从 ./myPjroject/target/*.jar 移动到 /usr/local/tomcat/webaps/fooApp/WEB-INF/lib

等等。

这个树然后不会被压缩,而是由后续的程序处理。

我已经阅读到安装插件(install mojo)可以复制JAR文件,但我没有看到任何文档表明它也可以复制我需要移动的其他文件。

英文:

I am converting a Java project from an any build process to Maven.

Maven can currently compile the jars from the project but to fully replace Ant I need to do two additional steps:

  1. Create a file tree
  2. Copy the compiled jars and other files stored in the project into desired directories created in step 1.

This tree needs to mirror the structure that both jars and resource files will appear in installed machine.

e.g. the contents of srs/foo/bar/scripts might need to be moved to /usr/local/myFoo/spam/bar/scripts

while jars might need to
go from ./myPjroject/target/*.jar to /usr/local/tomcat/webaps/fooApp/WEB-IBF/lib

ect

this tree does not then get zipped but processed by a subsequent program.

I have read that that install mojo can copy the jars but I have not seen any documentation showing that it can also copy the other files I need to move.

答案1

得分: 1

以下是翻译好的部分:

"I'm not sure about your question but if you only want to copy files creating target directories on the fly you can use the maven-antrun-plugin.

Something like

org.apache.maven.plugins
maven-antrun-plugin
1.7


copywar install
run







Is this what you are looking for?"

英文:

I'm not sure about your question but if you only want to copy files creating target directories on the fly you can use the maven-antrun-plugin.

Something like

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
	<execution>
		<id>copywar</id>
		<phase>install</phase>
		<goals>
			<goal>run</goal>
		</goals>
		<configuration>
			<target name="copy war into install folder">
				<copy 
					file="target/my.war"
					tofile="/install/my/${maven.build.timestamp}/my.war" />
			</target>
		</configuration>
	</execution>
</executions>
</plugin>		

Is this what you are looking for?

huangapple
  • 本文由 发表于 2023年4月19日 22:01:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76055438.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定