在这种情况下,我必须在预定义的xml文件中写入项目依赖项之一的工件名称,该文件将与项目jar一起保存,并驻留在项目的资源文件夹中。例如predefind.xml -
<project>
<projectName>somename</projectName>
<projectjar>
<name>some.jar</name>
</projectjar>
<dependantJarsInfo>
<folderName>dependant_jars</folderName>
<dependantJars>
<name>dependency.jar</name>
</dependantJars>
</dependantJarsInfo>
</plugin>
pom.xml
<project>
<groupId>com.mycom</groupId>
<artifactId>someproject</artifactId>
<packaging>jar</packaging>
<version>5.8.0.0</version>
<dependencies>
<dependency>
<groupId>com.mycom.</groupId>
<artifactId>dependency</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
</project>
我需要获得LATEST=1.2.0的全名,比如dependency 1.2.0,并在指定的标记处写入给定的predefined.xml文件。
<dependantJars>
<name>dependency.jar</name>
</dependantJars>
如果是的话,maven会这样做吗?如果没有,我应该采取什么替代办法来解决这一问题。
发布于 2016-08-29 05:10:26
伙计们,在对这个问题做了研究之后,我找到了解决办法。我使用两个maven插件来解决这个问题。
这个插件的使用-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>build-classpath</id>
<phase>validate</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<outputFile>target/classPath.txt</outputFile>
<includeArtifactIds>
dependency
</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>groovy-magic</id>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def theInfoName = "target/classPath.txt";
File theInfoFile = new File(theInfoName)
def words
def key
def value
if (!theInfoFile.exists()) {
println "File does not exist"
} else {
theInfoFile.eachLine { line ->
if (line.trim().size() == 0) {
return null
} else {
words = line
File theInfoFileto = new File(words)
ant.replace(file: "target/classes/myPackagepath/predefind.xml", token: "dependency.jar", value: theInfoFileto.getName())
}
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
希望这能帮上忙。
发布于 2016-08-19 13:53:14
我认为你实际上对你的问题采取了错误的方法。您应该尝试使用Maven性质。
示例
在pom.xml
中定义页面的名称:
<project>
<properties>
<package.name>dependency.jar</package.name>
</properties>
</project>
然后,当您想用命令行更改包的名称时,可以使用:
mvn -Dpackage.name=othername package ...
但是,如果不覆盖包的名称,仍然可以使用pom.xml
中定义的默认值
mvn package ...
其他关于这个的问题:
https://stackoverflow.com/questions/39040526
复制相似问题