17

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

[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.

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:

<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).

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.

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

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

1
  • I was using ByteOutputStream and getting this error. When I changed it to ByteArrayOutputStream, it worked like a charm. Never knew about JRE internal classes.
    – Anshuman
    May 4, 2015 at 10:15

2 Answers 2

16

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

    ...
    <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>
            ...
9

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.

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

Java 8 update

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

3
  • 2
    Well that was a special solution, what about other classes? For example Unsafe? There is not a good known replacement, and using it requires to depend on sun.* classes, what can we do in gradle? Nov 12, 2013 at 11:42
  • I'm unfortunately not familiar with that class. Might be a good topic for an entirely new question, though. Nov 12, 2013 at 11:52
  • 1
    Since Java 6 there's no longer a need to go external to find Base64 utilities: They are in javax.xml.bind.DatatypeConverter which is technically part of JAXB but you can use it regardless if you use JAXB or not.
    – peterh
    Dec 28, 2013 at 19:24

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.