Gradle: How to compile classes that use com.sun.xml.internal.bind. *?

I am in the process of converting an existing project from ant to Gradle.

Unfortunately, there is a Java class that uses com.sun.xml.internal.bind.DatatypeConverterImpl. Firstly, I'm going to study replacing this use, but at the moment I'm just wondering why Gradle cannot find this class, which leads to compilation failure.

Message

package com.sun.xml.internal.bind does not exist 

Note that it compiles fine in eclipse as well as using the javac ant task. JAVA_HOME is set to 1.6.0_27.

So, what is unique in Gradle that by default causes it to not find this class and how can someone solve this problem?




See the Java code snippet followed by the build.gradle file:

 final class Test{ private static final javax.xml.bind.DatatypeConverterInterface DTC = com.sun.xml.internal.bind.DatatypeConverterImpl.theInstance; ..... DTC.printDateTime(Calendar.getInstance()); } 


 apply plugin: 'java' apply plugin: 'application' mainClassName = "com.foo.bar.Test" sourceCompatibility = 1.6 version = '5.4.0' jar { manifest { attributes 'Implementation-Title': 'Foo', 'Implementation-Version': version, 'Implementation-Vendor': 'Bar' } } repositories { mavenCentral() } dependencies { compile group: 'commons-lang', name: 'commons-lang', version: '2.4' compile group: 'com.google.guava', name: 'guava', version: '10.0.1' compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.1.Final' compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' compile group: 'jdom', name: 'jdom', version: '1.0' compile group: 'log4j', name: 'log4j', version: '1.2.16' runtime group: 'antlr', name: 'antlr', version: '2.7.6' runtime group: 'backport-util-concurrent', name: 'backport-util-concurrent', version: '3.1' runtime group: 'c3p0', name: 'c3p0', version: '0.9.1.2' runtime group: 'cglib', name: 'cglib', version: '2.2' runtime group: 'commons-beanutils', name: 'commons-beanutils', version: '1.8.3' runtime group: 'commons-codec', name: 'commons-codec', version: '1.3' runtime group: 'commons-collections', name: 'commons-collections', version: '3.2.1' runtime group: 'commons-io', name: 'commons-io', version: '1.4' runtime group: 'commons-logging', name: 'commons-logging', version: '1.1.1' runtime group: 'dom4j', name: 'dom4j', version: '1.6.1' runtime group: 'javassist', name: 'javassist', version: '3.12.0.GA' runtime group: 'javax.transaction', name: 'jta', version: '1.1' runtime group: 'org.slf4j', name: 'slf4j-api', version: '1.6.2' runtime group: 'xerces', name: 'xerces', version: '2.4.0' runtime group: 'xerces', name: 'xercesImpl', version: '2.10.0' runtime group: 'xml-apis', name: 'xml-apis', version: '2.0.2' } 

EDIT

 C:\>gradle -v ------------------------------------------------------------ Gradle 1.0-milestone-3 ------------------------------------------------------------ Gradle build time: Monday, 25 April 2011 5:40:11 PM EST Groovy: 1.7.10 Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010 Ivy: 2.2.0 JVM: 1.6.0_27 (Sun Microsystems Inc. 20.2-b06) OS: Windows XP 5.1 x86 
+5
source share
5 answers
  • Solution No. 1:

Copy (do not move) rt.jar to another place other than <JDK_install_dir>\jre\lib\rt.jar (for example, c:\rt.jar ) and run your compiler as shown below:

 javac -cp c:\rt.jar your_file.java 
  • Decision number 2:

Compiling with the compiler option -XDignore.symbol.file=true

+3
source

Gradle also uses the javac Ant task. Compiling a class with build.gradle that contains only apply plugin: "java" works fine for me with Gradle 1.0-milestone-3 on Mac OS 10.6. Therefore, I think you are using Gradle with the JRE, not the JDK, or with 1.5, not 1.6.

Try putting the following into a build script and see if it works:

 // only available in JDK 1.6 println javax.tools.ToolProvider.getSystemJavaCompiler() 
+1
source

why not just use:

 javax.xml.bind.DatatypeConverter.printDateTime(Calendar.getInstance()); 
+1
source

I recently had the same issue you can find in this question about .

I solved this by referencing this library , which you can see that javax.xml.bind.DatatypeConverterInterface included here .

I packed the library and referenced it in my application.

0
source

reason: javac uses a special character table that does not include all Sun's proprietary classes. When javac compiles the code, it does not contact rt.jar by default. Instead, it uses a special lib / ct.sym symbol file with class stubs. decision:

 compileJava {options.bootClasspath = "$System.env.JAVA_HOME/jre/lib/rt.jar"} 
0
source

All Articles