Java 如何将maven项目配置为从config.properties文件读取?
我有一个带有DAO类的servlet,它具有以下构造函数:Java 如何将maven项目配置为从config.properties文件读取?,java,maven,properties,pom.xml,Java,Maven,Properties,Pom.xml,我有一个带有DAO类的servlet,它具有以下构造函数: public DAO() { env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:1389"); env.put(Contex
public DAO() {
env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:1389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS, "secret");
}
如何配置pom.xml文件以告诉maven使用config.properties?在这里,我决定添加插件块:
<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>${basedir}/src/main/resources/config.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
org.codehaus.mojo
属性maven插件
1.0-α-2
初始化
读取项目属性
${basedir}/src/main/resources/config.properties
查看一些示例/教程;)您好,您可以发布整个pom.xml文件吗?
<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>${basedir}/src/main/resources/config.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>