我在IntelliJ想法中为Jax-RS项目的Gradle设置遇到了问题
javax.servlet.ServletException: A MultiException has 2
exceptions. They are:
1. java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
2. java.lang.IllegalStateException: Unable to perform operation: create on com.mkl.rest.LionResource
这是我在
上测试过的虚拟代码@Path("lion")
public class LionResource
{
private BaseRest<AnyObject, AnyObjectDTO> baseRest = new BaseRest<AnyObject, AnyObjectDTO>(AnyObject.class, new AnyObjectDTO());
private AnyObjectFacade anyObjectFacade = new AnyObjectFacade(JPAConnection.getEntityManagerFactory());
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAnyObjects()
{
return baseRest.get();
}
build.gradle
group 'com.mkl'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'javax', name: 'javaee-api', version: '8.0'
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1'
compile group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.26'
compile group: 'org.glassfish.jersey', name: 'jersey-bom', version: '2.26'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet-core', version: '2.26'
compile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.26'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.6.Final'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.47'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
我尝试寻找解决方案,但对于第一个例外,我发现我应该在pom.xml中添加一些依赖项
How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9
但是,由于我使用的是Gradle,并且由于没有pom.xml而无法添加这些文件
关于第二个例外,我不确定“创建”是指什么?
答案 0 :(得分:3)
将此添加到您的build.gradle
:
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'