gpt4 book ai didi

java - 添加 Jersey MOXy 导致 Jetty 运行失败

转载 作者:行者123 更新时间:2023-12-01 11:16:46 25 4
gpt4 key购买 nike

我正在使用 Jersey、Hibernate 和嵌入式 Jetty 测试 REST。最初,我能够使用./gradlew clean jar && java -jar build/libs/<project>.jar启动一切。 。但是,我想支持 JSON 并从文档中了解到 MOXy 是 Jersey 的默认 JSON 提供程序。所以我在我的 build.gradle 中添加了以下内容文件:

compile 'org.glassfish.jersey.media:jersey-media-moxy:2.19'

之后,我尝试构建 jar 并启动 jetty 但遇到以下问题:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:284)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:238)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:273)
at java.util.jar.JarVerifier.update(JarVerifier.java:228)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
at java.util.jar.JarFile.getInputStream(JarFile.java:450)
at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:940)
at sun.misc.Resource.cachedInputStream(Resource.java:77)
at sun.misc.Resource.getByteBuffer(Resource.java:160)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:454)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

这是我的 build.gradle如果有帮助的话,请归档。

apply plugin: 'eclipse'
apply plugin: 'java'
apply plugin: 'jetty'

repositories {
jcenter()
}

dependencies {
compile 'org.slf4j:slf4j-api:1.7.12'

// Jetty
compile 'org.eclipse.jetty:jetty-server:9.3.1.v20150714'
compile 'org.eclipse.jetty:jetty-servlet:9.3.1.v20150714'

// Jersey
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.19'
compile 'org.glassfish.jersey.core:jersey-client:2.19'
compile 'org.glassfish.jersey.media:jersey-media-moxy:2.19'
compile 'org.glassfish.jersey.media:jersey-media-json-processing:2.19'
compile 'org.glassfish.jersey.media:jersey-media-multipart:2.19'
compile 'org.glassfish.jersey.media:jersey-media-sse:2.19'

// Hibernate
compile 'mysql:mysql-connector-java:5.1.36'
compile 'org.hibernate:hibernate-core:4.3.10.Final'
compile 'com.mchange:c3p0:0.9.5.1'

testCompile 'junit:junit:4.12'
}

jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Main-Class': 'com.domain.scaffolding.Main'
}
}

最佳答案

详细了解 gradle 如何构建 fat jar 后,解决问题的方法是修复 jar block :

jar {
from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
manifest {
attributes 'Main-Class': 'com.domain.scaffolding.Main'
}
}

关于java - 添加 Jersey MOXy 导致 Jetty 运行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31728508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com