[英]Maven: How to change path to target directory from command line?
Maven: How to change path to target directory from command line? Maven:如何从命令行更改目标目录的路径?
(I want to use another target directory in some cases) (在某些情况下我想使用另一个目标目录)
You should use profiles.您应该使用配置文件。
<profiles>
<profile>
<id>otherOutputDir</id>
<build>
<directory>yourDirectory</directory>
</build>
</profile>
</profiles>
And start maven with your profile并使用您的个人资料启动 Maven
mvn compile -PotherOutputDir
If you really want to define your directory from the command line you could do something like this ( NOT recommended at all ) :如果你真的想从命令行定义你的目录,你可以做这样的事情(根本不推荐):
<properties>
<buildDirectory>${project.basedir}/target</buildDirectory>
</properties>
<build>
<directory>${buildDirectory}</directory>
</build>
And compile like this :并像这样编译:
mvn compile -DbuildDirectory=test
That's because you can't change the target directory by using -Dproject.build.directory
那是因为您无法使用-Dproject.build.directory
更改目标目录
Colin is correct that a profile should be used. Colin 是正确的,应该使用配置文件。 However, his answer hard-codes the target directory in the profile.但是,他的回答对配置文件中的目标目录进行了硬编码。 An alternate solution would be to add a profile like this:另一种解决方案是添加这样的配置文件:
<profile>
<id>alternateBuildDir</id>
<activation>
<property>
<name>alt.build.dir</name>
</property>
</activation>
<build>
<directory>${alt.build.dir}</directory>
</build>
</profile>
Doing so would have the effect of changing the build directory to whatever is given by the alt.build.dir property, which can be given in a POM, in the user's settings, or on the command line.这样做的效果是将构建目录更改为由 alt.build.dir 属性给出的任何内容,该属性可以在 POM、用户设置或命令行中给出。 If the property is not present, the compilation will happen in the normal target directory.如果该属性不存在,则编译将在普通目标目录中进行。
My solution: 我的解决方案:
in pom.xml: 在pom.xml中:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <outputDirectory>${dir}</outputDirectory> </configuration> </plugin>
command in bash: bash中的命令:
mvn package -Ddir="/home/myuser/"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.