扩展引用库中的类时构建失败

时间:2013-05-20 08:09:15

标签: java maven inheritance build

美好的一天

我正在使用maven来构建我的java项目。我添加了一个log4j jar作为依赖项,并尝试extendRollingFileAppender类。我试图再次构建它,并且出乎意料地发生了错误。是否禁止从引用的库/ jar扩展类?

以下是所说的maven错误:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] bootstrap class path not set in conjunction with -source 1.6
c:\Users\jlim\Desktop\workspace\test-joven\src\main\java\com\joven\test\CustomRollingFileAppender.java:[3,23] error: package org.apache.log4j does not exist
[ERROR] c:\Users\jlim\Desktop\workspace\test-joven\src\main\java\com\joven\test\CustomRollingFileAppender.java:[5,47] error: cannot find symbol
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.045s
[INFO] Finished at: Mon May 20 15:56:14 CST 2013
[INFO] Final Memory: 12M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project test-joven: Compilation failure: Compilation failure:
[ERROR] bootstrap class path not set in conjunction with -source 1.6
[ERROR] c:\Users\jlim\Desktop\workspace\test-joven\src\main\java\com\joven\test\CustomRollingFileAppender.java:[3,23] error: package org.apache.log4j does not exist
[ERROR] c:\Users\jlim\Desktop\workspace\test-joven\src\main\java\com\joven\test\CustomRollingFileAppender.java:[5,47] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:

下面是我的pom.xml的依赖块:

<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>
  </dependencies>

谢谢!

1 个答案:

答案 0 :(得分:4)

log4j的范围是runtime

<scope>runtime</scope>

因此它仅在运行时可用,而不是在编译时。将其更改为compile(或删除它,因为编译是默认值)