从命令行

时间:2018-03-26 20:52:23

标签: java maven

我在我的pom.xml中使用maven-shade-plugin,我希望能够从命令行动态设置,如下所示:mvn -outputFile=C:/Users/Oscar/Desktop/MyJar.jar

我不想直接在pom.xml中对文件路径进行硬编码,因为我不想在回购中使用它。在我们的生产服务器上,我希望能够为阴影jar指定输出路径。在我的本地开发机器上,我希望能够指定自己的路径。

是否可以做这样的事情?

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <relocations>
                            <relocation>
                                <pattern>com.zaxxer.hikari</pattern>
                                <shadedPattern>io.github.hornta.lib.hikari</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>com.google.gson</pattern>
                                <shadedPattern>io.github.hornta.lib.gson</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>org.slf4j</pattern>
                                <shadedPattern>io.github.hornta.lib.slf4j</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>org.flywaydb.core</pattern>
                                <shadedPattern>io.github.hornta.lib.flywaydb</shadedPattern>
                            </relocation>
                        </relocations>
                       <outputFile>I NEED TO SET THIS PATH FROM COMMAND LINE(not having it in the repo)</outputFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>

2 个答案:

答案 0 :(得分:0)

我建议使用属性文件来设置值,然后将属性文件添加到.gitignore。这实际上是一个非常常见的用例,因为这样的值会因部署环境而异。有关此问题的讨论,请参阅this questionthis article

答案 1 :(得分:0)

您可以使用系统属性来定义outputFile

的值

更改pom.xml

中的行
<outputFile>${outputFilePath}</outputFile>

然后在命令行中使用变量

mvn -DoutputFilePath=C:/Users/Oscar/Desktop/MyJar.jar ...

您可以在properties

pom.xml中定义默认值
<properties>
    <outputFilePath>C:/Users/Oscar/Desktop/Default/MyJar.jar</outputFilePath>
</properties>
相关问题