2013-02-05 32 views
0

我不得不读财产多Maven项目共享,为此,我尝试使用属性 - Maven的插件,如:读取属性 - Maven的

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>properties-maven-plugin</artifactId> 
      <version>1.0-alpha-1</version> 
       <configuration> 
       <files> 
        <file>conf.properties</file> 
       </files> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>initialize</phase> 
        <goals> 
         <goal>read-project-properties</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     </plugins> 
     </build> 

<distributionManagement> 
    <snapshotRepository> 
     <id>snapshots</id> 
     <url>${nexusurl}</url> 
    </snapshotRepository> 
</distributionManagement> 
</project>  

和文件conf.properties包含:

nexusurl=http://localhost:8081/nexus/content/repositories/snapshots 

的问题是,使用MVN部署时,该属性nexusurl没有解决,错误跟踪结果是:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy 
(default- deploy) on project parent: Failed to deploy artifacts/metadata: No connector 
available to access repository snapshots (${nexusurl}) of type default using the 
available factories WagonRepositoryConnectorFactory -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute 
goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on 
project parent: Failed to deploy artifacts/metadata: No connector available to 
access repository snapshots (${nexusurl}) of type default using the available 
factories WagonRepositoryConnectorFactory 

我试图改变插件的执行阶段(验证,安装,部署),将插件的版本更改为1.0-alpha-2,但问题依然存在。

我会感谢任何援助。 谢谢,

+0

你的conf.properties似乎被忽略。你如何参考?如果你运行'mvn deploy -Dnexusurl = http:// localhost:8081/nexus/content/repositories/snapshots'会发生什么? – MrsTang

+1

不,属性文件不会被忽略,问题是用carlspring的回答描述的问题,部分中的值在最初加载POM时分配。 properties-maven-plugin只影响加载属性之后的插件执行。 –

回答

0

问题是,pom.xml被读取并与你的插件加载早得多的属性inteporlated。你可以在你的构建中为插件使用插件 - 例如插件之间的插件,但是你想做的事情不会像那样工作。

+0

您是否可以通过其他方式或插件传递属性? –

+0

插件将不适用于您的情况。 Maven将属性内插到加载的POM模型中的方式非常重要。为了达到这个目的,你必须通过命令行传递变量(我几乎看不出这样做的好处)。为了便于携带,您需要保留''URL的硬编码。 – carlspring

+0

把某些东西当作属性是有意义的,但是这个并不完全属于它们。 – carlspring