我尝试在安装了java 10的服务器上运行这个groovy脚本(在java 8上运行正常)。
@Grapes([
@Grab(group='org.slf4j', module='slf4j-api', version='1.7.25'),
@Grab(group='ch.qos.logback', module='logback-classic', version='1.2.3'),
@Grab(group='org.apache.commons', module='commons-lang3', version='3.7'),
@Grab(group='com.sparkjava', module='spark-core', version='2.7.2'),
@Grab(group='javax.xml.bind', module='jaxb-api', version='2.3.0'),
@Grab(group='com.sun.xml.bind', module='jaxb-core', version='2.3.0'),
@Grab(group='com.sun.xml.bind', module='jaxb-impl', version='2.3.0')
])
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.util.logging.Slf4j
import org.apache.commons.lang3.exception.ExceptionUtils
import spark.Route
import static spark.Spark.*
@Slf4j
class Server {
public static void main(String[] args) {
int serverPort = args.length > 0 ? args[0].toInteger() : 1001
log.info("start server at $serverPort ... ")
port(serverPort)
get("/hello", { req, rep -> "world" })
}
}
但我总是得到一个依赖缺失错误:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/opt/groovy-2.5.0-rc-3/lib/groovy-2.5.0-rc-3.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Caught: java.lang.NoClassDefFoundError: Unable to load class groovy.xml.jaxb.JaxbGroovyMethods due to missing dependency javax/xml/bind/JAXBContext
java.lang.NoClassDefFoundError: Unable to load class groovy.xml.jaxb.JaxbGroovyMethods due to missing dependency javax/xml/bind/JAXBContext
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
答案 0 :(得分:0)
看看JEP 320,我们知道某些Java EE模块已被删除:
从Java SE平台和Java SE平台删除Java EE和CORBA模块。 JDK
关于JAXB的stacktrace是Java EE平台的一部分。 我建议使用支持JDK 9/10的Groovy v3.x。
希望这会有所帮助。
答案 1 :(得分:0)
从日志来看,您的版本是2.5.0-rc-3
。
升级到> = 2.5.1
将解决该问题。
注意:无需导入javax.xml.bind