【问题标题】:Maven configuration not work [duplicate]Maven配置不起作用[重复]
【发布时间】:2015-12-28 12:09:04
【问题描述】:

我希望能够为不同的环境使用不同的 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>

【问题讨论】:

    标签: java maven tomcat web.xml


    【解决方案1】:

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

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

    【讨论】:

    • 我添加了 EDIT 并且项目运行成功,但记录器不起作用!
    猜你喜欢
    • 2013-07-04
    • 2018-09-03
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    相关资源
    最近更新 更多