【问题标题】:build fails when a class in a referenced library is extended扩展引用库中的类时构建失败
【发布时间】:2013-05-20 08:09:14
【问题描述】:

美好的一天

我正在使用 maven 来构建我的 java 项目。我添加了一个 log4j jar 作为依赖项,并尝试 extend 它的 RollingFileAppender 类。我尝试再次构建它,但令人惊讶的是发生了错误。是否禁止从引用的库/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>

谢谢!

【问题讨论】:

  • 请显示您的 pom 文件,因为我假设您添加了范围测试的依赖项。
  • 好的,请稍等,我将编辑我的帖子。

标签: java maven inheritance build


【解决方案1】:

log4j的作用域是runtime:

<scope>runtime</scope>

所以它只在运行时可用,而不是在编译时可用。将其更改为compile(或删除它,因为编译是默认设置)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多