我在哪里可以存储此属性以供Maven和Java使用?

Dav*_*e A 4 java properties maven

我正在使用Maven 3.0.3和Java 6.我想把一个WSDL URL属性放在Maven构建过程可以访问的地方,我的运行时Java代码(我正在构建一个Maven JAR项目)也可以访问.我该如何构建/配置?在我的运行时Java代码中,我有类似的东西

String wsdlUrl = getProperty("wsdl.url");
Run Code Online (Sandbox Code Playgroud)

在Maven中,我想在插件中访问WSDL URL,如此...

                    <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>jaxws-maven-plugin</artifactId>
                            <executions>
                                    <execution>
                                            <goals>
                                                    <goal>wsimport</goal>
                                            </goals>
                                            <configuration>
                                                    <wsdlUrls>
                                                            <wsdlUrl>${wsdl.url}</wsdlUrl>
                                                    </wsdlUrls>
                                                    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                                                    <packageName>org.myco.bsorg</packageName>
                                            </configuration>
                                    </execution>
                            </executions>
                    </plugin>
Run Code Online (Sandbox Code Playgroud)

npe*_*npe 5

.propertiessrc/main/resources目录中创建一个文件.

在pom.xml里面

使用property-maven-plugin并从此文件加载属性,如下所示(在使用站点之后):

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>src/main/resources/common.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

来自Java

使用Properties#load(InputStream)并加载如下所示的属性:

String propertiesFileName = "/common.properties";

Properties properties = new Properties();
InputStream inputStream = this.getClass().getClassLoader()
    .getResourceAsStream(propertiesFileName);

properties.load(inputStream);
Run Code Online (Sandbox Code Playgroud)