My code contains import sun.misc.URLClassPath
and works normally on Java 8.
I am now moving to Java 11 and the code does not work anymore. It is caused by the sun.mics
package was moved into JDK internal package.
Then, I use --add-exports
option added to the Java compiler (javac) exports a package to my module to continue using it (for a short time while waiting for the official fixing by my team).
Here is the pom info
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArgs>
<arg>--add-exports=java.base/jdk.internal.misc=com.myapp.af.util</arg>
<arg>--add-opens=java.base/jdk.internal.misc=com.myapp.af.util</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
When I execute mvn compile
I've got:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/apps/src/main/java/com/myapp/af/util/AgentClassLoaderUtil.java:[6,16] cannot find symbol
symbol: class URLClassPath
location: package sun.misc
[ERROR] /D:/apps/src/main/java/com/myapp/af/util/AgentClassLoaderUtil.java:[35,17] cannot find symbol
symbol: class URLClassPath
location: class com.myapp.af.util.AgentClassLoaderUtil
[ERROR] /D:/apps/src/main/java/com/myapp/af/util/AgentClassLoaderUtil.java:[35,37] cannot find symbol
symbol: class URLClassPath
location: class com.myapp.af.util.AgentClassLoaderUtil
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.091 s
[INFO] Finished at: 2023-06-15T16:27:46+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project apps: Compilation failure: Compilation failure:
[ERROR] /D:/apps/src/main/java/com/myapp/af/util/AgentClassLoaderUtil.java:[6,16] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: package sun.misc
[ERROR] /D:/apps/src/main/java/com/myapp/af/util/AgentClassLoaderUtil.java:[35,17] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: class com.myapp.af.util.AgentClassLoaderUtil
[ERROR] /D:/apps/src/main/java/com/myapp/af/util/AgentClassLoaderUtil.java:[35,37] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: class com.myapp.af.util.AgentClassLoaderUtil
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Am I missing something?