2011-11-16 64 views
5

外面有没有办法来定义POM文件超出了我的Maven的配置文件,但在.m2目录/ settings.xml中没有
我想定义他们在单独的XML文件里面应用(方式与Maven 2高效工作和3),因为我使用maven 2,并打算很快切换到3。定义Maven的配置文件POM

回答

1

直到Maven 2.2.1您可以将您的配置文件定义到profiles.xml文件中作为单独的文件,但使用Maven 3时,此机会已被删除。问题是为什么你需要一个单独的文件的配置文件?

+4

因为我有很多配置文件,并且每个配置文件都包含很多属性,并且pom文件越来越多这么大。 –

+0

如果使用包含配置文件的超级pom,假设它们适用于不同的项目类型,那么如何使用它?然后,您的项目poms可以使用该父项目,而不必重新定义所有这些常见行为。 – RonU

+0

这种方式的网址请在单独的答案是更可取的? –

1

您可能想要通过构建配置文件上的this maven documentation,其中描述了配置文件的类型以及每个配置文件的使用方式。

正如我所看到的,如果您想使用maven 3,则无法在pom.xmlsettings.xml之外定义配置文件。

0

我最近正在将一个应用程序从maven2迁移到maven3。有了maven 3,就不可能拥有外部配置文件。但是可以做的是拥有外部属性文件。这可以通过行家 - 属性 - 插件来实现

<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/

0
<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> 

并添加目录( dev,prod,test)

相关问题