jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
36 stars 6 forks source link

Could not find artifact com.sun:tools:jar:1.7.0 #119

Closed jferard closed 6 years ago

jferard commented 6 years ago

After Ubuntu upgrade, I got the following error:

$> mvn clean install
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
...
[ERROR] Failed to execute goal on project fastods-testlib: Could not resolve dependencies for project com.github.jferard:fastods-testlib:jar:0.6.1-SNAPSHOT: Could not find artifact com.sun:tools:jar:1.7.0 at specified path /usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar -> [Help 1]

After some digging, JRE was update to version 11, which does not know tools.jar (modularity). Workaround on linux:

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" mvn clean install

Should update README.

jferard commented 5 years ago

There are some visitors probably trying to solve the same problem. Here's a summary of the solution.

First mvn dependency:tree to find which lib needs com.sun.tools:jar:

\- org.apache.odftoolkit:simple-odf:jar:0.8.2-incubating:compile
[INFO]    \- org.apache.odftoolkit:odfdom-java:jar:0.8.11-incubating:compile
[INFO]       +- org.apache.odftoolkit:taglets:jar:0.8.11-incubating:compile
[INFO]       |  \- com.sun:tools:jar:1.7.0:system

Second, check the POM for taglets. You'll find the dependency. Luckily, the dependency is add by a profile activation:

<profiles>
    <profile>
        <id>tools.jar</id><!-- For JDK 7 and later - with Oracle Brand --> 
        <activation>
            <property>
                <name>java.vendor</name>
                <value>Oracle Corporation</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>1.7.0</version>
                <scope>system</scope>
                <systemPath>${java.home}/../lib/tools.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>tools-sun.jar</id><!-- For JDK 6 and OpenJDK - with Sun Brand --> 
        <activation>
            <property>
                <name>java.vendor</name>
                <value>Sun Microsystems Inc.</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>1.5.0</version>
                <scope>system</scope>
                <systemPath>${java.home}/../lib/tools.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>

Three, set a property yo deactivate those two profiles:

<properties>
    <java.vendor>prevent odftoolkit from messing the build</java.vendor>
</properties>

This is a dirty hack, but it works!