I've got a very simple program:
Test.java
:
package com;
import sun.misc.Contended;
public class Test {
}
and pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>Test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
</project>
when I put mvn compile
I've got:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project proj: Compilation failure
[ERROR] /home/john/Desktop/proj/src/main/java/com/Test.java: cannot find symbol
[ERROR] symbol: class Contended
[ERROR] location: package sun.misc
Why?
Because, sun.misc
moved to jdk.internal.misc
and they are private package to JDK.
... friend interfaces should be moved out of 'sun.misc' and located in a truly private package. This is so that they are not part of the proposed to be exported 'sun.misc' package.
You can use --add-exports
and --add-opens
to gain access to internal API.
In your case, you can add following in your pom.xml
<compilerArgs>
<arg>--add-exports</arg>
<arg>java.base/jdk.internal.misc=<<your.module>></arg>
</compilerArgs>
Please note, you need to change <<your.module>>
to your actual module name.
Reference : - JEP-261:Module System