asanelder
asanelder

Reputation: 51

can't find the symbol from tools.jar

code below

import com.sun.tools.javac.util.Abort;

public class Test {
    public static void main(String[] args) {
        System.out.println("hello world");
    }
}

use javac to compile this file, compile error like this

com.sun.tools.javac.util doesn't exist

I'm using mac, here is my java -version output

openjdk version "1.8.0_265"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.265-b01, mixed mode)

Upvotes: 0

Views: 33

Answers (1)

jhamon
jhamon

Reputation: 3691

The package com.suncontains Oracle private JDK classes (see more here, and the offical statement).

You are running OpenJdk and this JDK doesn't include Sun's packages.

2 solutions:

  • Execute your program with Oracle JDK
  • Don't use those classes.

Note that using com.sun packages in an application is seen as a bad practice for this exact reason.

Upvotes: 0

Related Questions