23

I want to compile java code that uses some Java's deprecated "sun" packages and Gradle compile task fails with this error

error: package com.sun.xml.internal.ws.developer does not exist

I am using Hotspot JDK and I can see this package there (so it actually exists - in rt.jar file) I also tried to add rt.jar itself into Gradle dependencies:

compile files( 'C:/Program Files/Java/jdk1.7.0_05/jre/lib/rt.jar')

but with no effect

here is my gradle -v output:

------------------------------------------------------------
Gradle 1.2
------------------------------------------------------------

Gradle build time: Streda, 2012, september 12 10:46:02 UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.7.0_05 (Oracle Corporation 23.1-b03)
OS: Windows 7 6.1 amd64

I also tried to add jaxws-rt.jar to classpath - no effect neither

I would really appreciate any help

thanks

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
user1746915
  • 331
  • 1
  • 3
  • 8

1 Answers1

18

It's Oracle's intent that these classes be inaccessible at compile-time.

See the response to this javac bug report.

For a likely solution, see Using internal sun classes with javac . The javac -XDignore.symbol.file switch should fix this - but I'm a gradle newb, and don't see how to feed this to gradle's JavaCompile. My best guess is

  apply plugin: 'java' 
  compileJava.options.useAnt = true 
  compileJava.options.compilerArgs << "-XDignore.symbol.file" 

Incidentally, ct.sym (referred to in the link) appears to be a jar-file that lists, as class stubs, all the accessible classes.

Community
  • 1
  • 1
Ed Staub
  • 15,480
  • 3
  • 61
  • 91
  • Gradle doesn't use a class loader for this, and it doesn't exclude anything. It just invokes the Java compiler API with all available information (e.g. compile class path). I believe it's the Java compiler (API) that disallows usage of certain internal JDK packages. Here is a reported case where explicitly adding rt.jar solved the problem: http://forums.gradle.org/gradle/topics/package_sun_text_normalizer_does_not_exist – Peter Niederwieser Oct 25 '12 at 12:53
  • Peter: I tried it on a new project (to make sure I did not reuse my old mistakes) and it still does not work :( – user1746915 Oct 25 '12 at 13:25
  • also when I build my project in Idea, it works – user1746915 Oct 25 '12 at 13:29
  • @PeterNiederwieser - thanks for showing the way - see updated answer with specifics, and (hopefully) a partial better solution. I cross-posted onto the forum thread in hope that it's useful. – Ed Staub Oct 25 '12 at 13:39
  • @user1746915 - IDE's do all sort of tricks with the compiler. If you're trying to come at this from a neutral perspective, to confirm that gradle isn't causing the problem, try compiling a tiny .java with the problem import from the command line. – Ed Staub Oct 25 '12 at 14:13
  • Compiling from the command line isn't the same, because by default, Gradle uses the Java compiler API, which doesn't behave exactly the same as the Oracle JDK command-line compiler. – Peter Niederwieser Oct 25 '12 at 19:41
  • It works :-) apply plugin: 'java' compileJava.options.useAnt = true compileJava.options.compilerArgs << "-XDignore.symbol.file" Thank you – user1746915 Oct 26 '12 at 10:22
  • 6
    useAnt has been removed in recent versions of Gradle. "`options.fork = true; options.forkOptions.executable = 'javac'`" worked for me. See: https://discuss.gradle.org/t/java-compiler-ignore-symbol-file/8774 – Luke Quinane Jun 28 '16 at 01:46
  • I am struggling in same issue but I am using Ant build, my solution is to update the javac tag in the build.xml such that: – RAY Feb 16 '23 at 07:40