有没有一种方法可以在不使用.m2/settings.xml文件的情况下,在应用程序内部的单独xml文件中定义我的maven配置文件?这样可以更有效地使用maven 2和3,因为我正在使用maven 2并打算很快切换到3。
您可能需要查看此Maven文档,了解有关构建配置文件的类型及其用法的详细信息。
据我所知,如果您想使用Maven 3
,则无法在pom.xml
或settings.xml
之外定义配置文件。
在Maven 2.2.1之前,您可以将配置文件定义为一个单独的文件profiles.xml,但是在Maven 3中,这个机会已经被取消了。问题是为什么需要一个单独的文件来存储配置文件?
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>dev</build.profile.id>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<build.profile.id>prod</build.profile.id>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<build.profile.id>test</build.profile.id>
</properties>
</profile>
</profiles>
<filters>
<filter>src/test/resources/${build.profile.id}/config.properties</filter>
</filters>
最近我正在将一个应用程序从maven2迁移到maven3。在maven 3中,没有外部配置文件的可能性。但是可以使用外部属性文件来实现这一点。这可以通过maven-properties-plugin来实现。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<!-- Associate the read-project-properties goal with the initialize phase,
to read the properties file. -->
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>../com.tak/build.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
所以在这里我解释了如何做到这一点 http://programtalk.com/java/migrate-from-maven2x-to-maven3x/