Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 528
Sergey Avatar asked Oct 29 '12 12:10

Sergey


People also ask

How do you fix the container Maven dependencies references non existing library?

Try to update your Maven configuration : In the Project Explorer, right-click on the project, Maven -> Update project. If the problem still remains, try to clean your project: right-click on your pom. xml, Run as -> Maven build (the second one). Enter "clean package" in the Goals fields.

How do I fix missing Maven dependencies in Eclipse?

My problem solved by right click on project -> Maven -> Update project. Then the Maven Dependencies appear on the project explore. Save this answer.

Why Maven dependencies are not showing in STS?

You can find this in Window > Preferences > Maven > User Settings , and then point Global Settings to your external maven settings. xml . Then i removed the broken projects and re-added them, and the Maven Dependencies library appeared again. Save this answer.


2 Answers

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>
            ...
like image 73
karmakaze Avatar answered Sep 18 '22 04:09

karmakaze


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.

like image 21
Henrik Aasted Sørensen Avatar answered Sep 19 '22 04:09

Henrik Aasted Sørensen