Dav*_* L. 5 java eclipse maven-2 classpath gradle
我正在将现有项目从ant转换为Gradle.
不幸的是,有一个Java类使用com.sun.xml.internal.bind.DatatypeConverterImpl.有一件事我会考虑更换这种用法,但此时我只是好奇为什么Gradle找不到那个类,导致编译失败.
信息是
package com.sun.xml.internal.bind does not exist
Run Code Online (Sandbox Code Playgroud)
请注意,它在eclipse中编译良好以及使用javac ant任务.JAVA_HOME设置为1.6.0_27.
那么Gradle的独特之处在于默认情况下它会导致它找不到这个类,怎么可能有人解决这个问题呢?
请参阅Java代码段,后跟build.gradle文件:
final class Test{
private static final javax.xml.bind.DatatypeConverterInterface DTC = com.sun.xml.internal.bind.DatatypeConverterImpl.theInstance;
.....
DTC.printDateTime(Calendar.getInstance());
}
Run Code Online (Sandbox Code Playgroud)
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'
}
Run Code Online (Sandbox Code Playgroud)
编辑
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
Run Code Online (Sandbox Code Playgroud)
Gradle 还使用了javac
下面的 Ant 任务。build.gradle
在 Mac OS 10.6 上使用 Gradle 1.0-milestone-3 编译仅包含的类apply plugin: "java"
对我来说效果很好。所以我最好的猜测是您正在使用 JRE 而不是 JDK 运行 Gradle,或者使用 1.5 而不是 1.6。
尝试将以下内容放入构建脚本中并查看它是否有效:
// only available in JDK 1.6
println javax.tools.ToolProvider.getSystemJavaCompiler()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5313 次 |
最近记录: |