0

I have a maven project which needs

import com.sun.tools.classfile.Dependencies;

I can build it successfully in IntelliJ. But when I build it outside using "mvn clean install". I got the error "Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ... package com.sun.tools.classfile does not exist".

Package com.sun.tools.classfile belongs to $JAVA_HOME/lib/tools.jar. and it exists under that directory. Seems that Intellij can find it but maven build could not find it. Anyone knows why it could happen?

My machine is Macbook pro. Here are the java version and maven verion on my box.

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)

mvn -version
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /Users/wuming/apache-maven-3.8.1
Java version: 1.8.0_292, vendor: AdoptOpenJDK, runtime: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"

Thanks

Robert
  • 39,162
  • 17
  • 99
  • 152
Ming Wu
  • 87
  • 9
  • 1
    As far as I remember `tools.jar` is part of the JDK, not of the JRE and the path Maven uses points to the JRE. – Robert Aug 04 '21 at 15:41
  • @Robert, you are right that tools.jar is part of the JDK. But from https://maven.apache.org/install.html, the output of mvn -version is expected, it should point to the JRE, not JDK. – Ming Wu Aug 04 '21 at 16:23
  • One question is coming into my mind. Why do you need that class? What kind of problem are you trying to solve? – khmarbaise Aug 04 '21 at 16:59
  • @khmarbaise, thanks for pointing that out. I actually don't need to use that class. It was added automatically by intellij – Ming Wu Aug 04 '21 at 17:36
  • If it was added by IDEA you have used a class `Dependencies` in your code... – khmarbaise Aug 05 '21 at 08:21

1 Answers1

-1

If you added maven via brew install maven you will get this type of issue.

Better to get the apache maven and setup the path variables accordingly.

To setup the path variables check this

Nipuna Upeksha
  • 348
  • 3
  • 15