gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 01:55:30 25 4
gpt4 key购买 nike

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

String wsdlUrl = getProperty("wsdl.url");

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

最佳答案

src/main/resources 目录中创建一个 .properties 文件。

在 pom.xml 中

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

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

来自 Java

使用Properties#load(InputStream)并像这样加载属性:

String propertiesFileName = "/common.properties";

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

properties.load(inputStream);

关于java - 我在哪里可以存储此属性以供 Maven 和 Java 使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10885077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com