pom.xml
ファイルのコマンドラインから引数を渡すことはできますか?例えば 私はmvn ... argument
pom.xmlのプロパティとしてMavenからのコマンドライン引数を渡す
を実行するとのpom.xml
<properties>
<myproperty> here should add argument from command line</myproperty>
</properties>
では、助けてくれてありがとう。あなたの財産の例えば
pom.xml
ファイルのコマンドラインから引数を渡すことはできますか?例えば 私はmvn ... argument
pom.xmlのプロパティとしてMavenからのコマンドライン引数を渡す
を実行するとのpom.xml
<properties>
<myproperty> here should add argument from command line</myproperty>
</properties>
では、助けてくれてありがとう。あなたの財産の例えば
が行います。全体のプロパティ定義の周り
mvn install "-Dmyproperty=my property from command line"
注引用符を。プロパティにスペースが含まれている場合は、それらが必要になります。この中
また、pomとコマンドラインの両方にプロパティがある場合、コマンドラインには優先順位。これは、オーバーライド可能なデフォルトを提供するのに便利です。 –
<project>
.....
<profiles>
<profile>
<id>linux64</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build_os>linux</build_os>
<build_ws>gtk</build_ws>
<build_arch>x86_64</build_arch>
</properties>
</profile>
<profile>
<id>win64</id>
<activation>
<property>
<name>env</name>
<value>win64</value>
</property>
</activation>
<properties>
<build_os>win32</build_os>
<build_ws>win32</build_ws>
<build_arch>x86_64</build_arch>
</properties>
</profile>
</profiles>
.....
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<environments>
<environment>
<os>${build_os}</os>
<ws>${build_ws}</ws>
<arch>${build_arch}</arch>
</environment>
</environments>
</configuration>
</plugin>
.....
引数なしでpomを実行した場合の例mvn clean install
のデフォルトプロファイルが実行されます。
mvn -Denv=win64 clean install
Win64のプロファイルで実行すると実行されます。
あなたはプロジェクトファイルなどの変数名を付けることができhttp://maven.apache.org/guides/introduction/introduction-to-profiles.html
を参照してください。たとえば、あなたが設定をプラグインに次のように1つのタグだけを与える: -
<projectFile>${projectName}</projectFile>
次に、コマンドラインで使用すると、パラメータとしてプロジェクト名を渡すことができます: -
mvn [your-command] -DprojectName=[name of project]
mvnコマンドでブラウザの名前と環境を提供したい。私が提供しないと、デフォルトを選択します。どうやってするか? – paul
を、私はこれを解決するためのプラグインのプロパティを使用。
プロパティはpomで定義され、my.propertiesファイルに書き出され、そこでJavaコードからアクセスできます。私の場合は
ポンポンでプロパティファイルをMavenのtestOutputDirectoryに書かれているので、それは、このプロパティファイルをアクセスする必要があるテストコードです:あなたはプロパティは、あなたのことでアクセスできるようにしたい場合は
<configuration>
<outputFile>${project.build.testOutputDirectory}/my.properties</outputFile>
</configuration>
使用OUTPUTDIRECTORYアプリのコード:充実した例をお探しの方に
<configuration>
<outputFile>${project.build.outputDirectory}/my.properties</outputFile>
</configuration>
私はプロパティタグの命名がポンポンファイルの別の場所でそれらを取得する機能にどのように影響するかを理解していなかったとして(それは私にこの作業を取得するためにいじるのビットを取りました)、私のポンはf ollows:
<dependencies>
<dependency>
...
</dependency>
</dependencies>
<properties>
<app.env>${app.env}</app.env>
<app.port>${app.port}</app.port>
<app.domain>${app.domain}</app.domain>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.testOutputDirectory}/my.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
、コマンドラインで:
mvn clean test -Dapp.env=LOCAL -Dapp.domain=localhost -Dapp.port=9901
したがって、これらのプロパティは、Javaコードからアクセスできます。
java.io.InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("my.properties");
java.util.Properties properties = new Properties();
properties.load(inputStream);
appPort = properties.getProperty("app.port");
appDomain = properties.getProperty("app.domain");
未直接何を求めているが、[達人プロファイル](http://maven.apache.org/guides/introduction/introduction-to-profiles.html)はこのために役立つかもしれません – Sig
私はプロファイルについて知っています。私はmaven-soapui-pluginを使用しています。 ... projectFile>にはプロジェクトの名前が定義されています。私は約10のプロジェクトを持っていますし、私はすべてのプロジェクトの新しいプロファイルをしたくありません。私はmvnを実行する引数を使用する... project1とmvnを実行するproject2 ... project2を実行するproject2 –
hudi