我有一个带有 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(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS, "secret");
}
我在 source/main/resources 中编写了以下 config.properties 文件:
INITIAL_CONTEXT_FACTORY=com.sun.jndi.ldap.LdapCtxFactory
PROVIDER_URL=ldap://localhost:1389
SECURITY_AUTHENTICATION=simple
SECURITY_PRINCIPAL=cn=Directory Manager
SECURITY_CREDENTIALS=secret
如何配置 pom.xml 文件来告诉 maven 使用 config.properties ?
最佳答案
在这里,我决定添加插件 block :
<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>
关于java - 如何配置 Maven 项目以从 config.properties 文件中读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31293905/