java Maven 无法编译依赖于 rt.jar 的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13121954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:34:36  来源:igfitidea点击:

Maven can't compile class which depends on rt.jar

javamavencontinuous-integration

提问by Sergey

CI-server (Hudson), for which I am responsible, builds Maven project. After the last commit, the build failed:

我负责的 CI-server (Hudson) 构建 Maven 项目。最后一次提交后,构建失败:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] \hudson\jobs\path to my class\MyClass.java:[33,62] package com.sun.xml.internal.messaging.saaj.packaging.mime.util does not exist
[ERROR] \hudson\jobs\path to my class\MyClass.java:[75,5] cannot find symbol
        symbol  : class BASE64EncoderStream
        location: class |fullname of MyClass|
[ERROR] \hudson\jobs\path to my class\MyClass.java:[75,38] cannot find symbol
        symbol  : class BASE64EncoderStream
        location: class |fullname of MyClass|
[INFO] 3 errors

Required class (com.sun.xml.internal.messaging.saaj.packaging.mime.util.BASE64EncoderStream) is situated in rt.jar.

所需的类 (com.sun.xml.internal.messaging.saaj.packaging.mime.util.BASE64EncoderStream) 位于 rt.jar 中。

I tried (In accordance with the instructions at http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies) to add system dependency in project's pom.xml:

我尝试(根据http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies上的说明)在项目的 pom.xml 中添加系统依赖项:

<dependency>
    <groupId>dummy</groupId>
    <artifactId>dummy</artifactId>
    <version>1</version>
    <scope>system</scope>
    <systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>

It did not help.

它没有帮助。

The most interesting is that all files compiled fine on the local machine of my collegue (he use Eclipse build-in compiler).

最有趣的是,所有文件都在我同事的本地机器上编译得很好(他使用 Eclipse 内置编译器)。

In internet I found the same question (link: http://maven.40175.n5.nabble.com/Why-can-t-Maven-find-com-sun-xml-internal-messaging-saaj-util-ByteOutputStream-class-td107361.html). The last answer was that the reason for this trouble is Oracle's Java compiler.

在互联网上我发现了同样的问题(链接:http: //maven.40175.n5.nabble.com/Why-can-t-Maven-find-com-sun-xml-internal-messaging-saaj-util-ByteOutputStream-类-td107361.html)。最后的答案是,这个麻烦的原因是Oracle的Java编译器。

So, I changed Oracle's jdk to OpenJDK, but it did not help.

因此,我将 Oracle 的 jdk 更改为 OpenJDK,但没有帮助。

Does someone have any suggestions on how to solve this problem?

有人对如何解决这个问题有任何建议吗?

采纳答案by Henrik Aasted S?rensen

The missing class seems to be JRE internal (as indicated in its namespace), and should not be referenced from your code. It is probably only available on specific platforms or JRE versions.

缺少的类似乎是 JRE 内部的(如其命名空间所示),不应从您的代码中引用。它可能仅在特定平台或 JRE 版本上可用。

Consider replacing it with another Base64 encoder class, e.g. one from the Apache Commmons Codec project.

考虑用另一个 Base64 编码器类替换它,例如来自Apache Commmons Codec 项目的一个

Java 8 update

Java 8 更新

Java 8 finally introduced a Base64 class in the public part of the JDK: java.util.Base64.

Java 8 终于在 JDK 的公共部分引入了一个 Base64 类:java.util.Base64.

回答by karmakaze

Need to specify -XDignore.symbol.fileand add rt.jar dependency and <fork>true</fork>as the compiler plugin will otherwise silently drop any -XD flags: e.g.

需要指定-XDignore.symbol.file并添加 rt.jar 依赖项,<fork>true</fork>否则编译器插件将默默地删除任何 -XD 标志:例如

    ...
    <dependency>
        <groupId>groupid</groupId>
        <artifactId>artifiactId</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${java.home}/lib/rt.jar</systemPath>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArgs>
                    <arg>-XDignore.symbol.file</arg>
                </compilerArgs>
                <fork>true</fork>
            </configuration>
            ...