Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从外部文件读取属性-Maven_Maven_Maven 2 - Fatal编程技术网

从外部文件读取属性-Maven

从外部文件读取属性-Maven,maven,maven-2,Maven,Maven 2,我必须阅读多个maven项目共享的属性,为此,我尝试使用属性maven插件,如: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <version>1.0-alpha-1</version>

我必须阅读多个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>    
问题在于,使用mvn deploy时,未解决属性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,但问题仍然存在

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

问题在于pom.xml的读取和属性的关联要比插件加载的时间早得多。您可以将插件用于构建中的值,例如插件之间的值,但您尝试执行的操作不会像这样工作。

您的conf.properties似乎被忽略。你指的是什么?如果运行
mvn deploy-dnexusure会发生什么=http://localhost:8081/nexus/content/repositories/snapshots
?不,属性文件没有被忽略,问题是carlspring的答案描述了什么,部分中的值是在POM最初加载时分配的。properties maven插件只影响加载属性点之后的插件执行。您是否可以通过其他方式或插件传递属性?插件不适用于您的情况。Maven将属性插值到加载的POM模型中的方式才是重要的。为了让它工作,您必须通过命令行传入变量(我几乎看不出这样做有什么好处)。出于可移植性的考虑,您需要对
URL进行硬编码。将某些内容作为属性是有意义的,但这一项不在其中。请将
放入父POM文件中。然后扩展它。这将为该设置提供一个中心位置。更易于维护,并且非常接近您尝试执行的操作。感谢您的回复,因为解决方案我们可以将分发管理放在所有项目的父POM中,这有助于维护硬编码属性列表,或者将属性列表放在maven的settings.xml下的properties部分
[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