Maven配置不起作用

时间:2015-09-30 15:56:08

标签: java maven tomcat web.xml

我希望能够针对不同的环境使用不同的log4j配置。如果我在tomcat(localhost:8080)中运行项目需要使用dev.properties,如果我在产品服务器中运行项目需要使用prod.properties。我发现如here所述我复制了代码最佳答案,但我的pom.xml显示错误:

<build>
    <finalName>secure-exam</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
            <executions>
                <execution>
                    <id>log4j</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>output_directory</outputDirectory>
                        <resources>
                            <resource>${log4j.file}</resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <log4j.file>/home/name/Workspace/spring/src/main/resources/console_log4j.properties</log4j.file>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <log4j.file>/home/name/Workspace/spring/src/main/resources/fiile_log4j.properties</log4j.file>
        </properties>
    </profile>
</profiles>

这是pom.xml文件

中的错误显示
show cannot resolve sympol `copy-resources`
element outputDirectory is not allowed here
element resources is not allowed here
element resource is not allowed here

请告诉我如何在我的pom.xml中配置它?

修改

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

1 个答案:

答案 0 :(得分:3)

您没有正确复制它。您需要使用资源插件而不是编译器插件

    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <executions>