Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.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
Java 如何将maven项目配置为从config.properties文件读取?_Java_Maven_Properties_Pom.xml - Fatal编程技术网

Java 如何将maven项目配置为从config.properties文件读取?

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

我有一个带有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");
}

如何配置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>