我编写了一个Jersey客户端,该客户端与第3方服务进行通信,如果我从Eclipse运行它,它也可以工作,但是如果我运行jar文件,它将抛出MessageBodyProviderNotFoundException。
我的build.gradle:
// Apply the java plugin to add support for Java
apply plugin: 'java'
version = '1.0'
// In this section you declare where to find the dependencies of your project
repositories {
jcenter()
}
//create a single Jar with all dependencies
task createJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'MeteorDesk Whatsapp Images Parser',
'Implementation-Version': version,
'Main-Class': 'controller.ImagesParser'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
} …Run Code Online (Sandbox Code Playgroud) 我有一个Java项目,带有用于REST服务的嵌入式jetty服务器和jersey库.我正在使用Intellij来运行项目及其工作.问题是当我尝试执行生成的jar文件时.
所以我编写了一个在build.gradle文件中生成jar文件的任务.以下是build.gradle中的任务
task fatJar(type: Jar) {
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': 1.0
attributes 'Main-Class': 'EmbeddedJetty.EmbeddedJettyMain'
}
}
Run Code Online (Sandbox Code Playgroud)
运行以下命令时会生成jar文件
gradle clean build fatJar
Run Code Online (Sandbox Code Playgroud)
当我尝试使用该命令生成的jar文件时,我面临以下错误
java -jar projectname.rar
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) …Run Code Online (Sandbox Code Playgroud) 使用OpenSAML 3时,必须首先opensaml-saml-impl使用以下代码行从工件加载组件:
InitializationService.initialize();
Run Code Online (Sandbox Code Playgroud)
这用于java.util.ServiceLoader加载任何实现的类型Initializer.
当我编写测试并运行它时mvn integration-test,这工作正常,我可以看到所有内容都已加载:
Assert.assertTrue(
XMLObjectProviderRegistrySupport
.getUnmarshallerFactory()
.getUnmarshallers()
.size() > 400);
Run Code Online (Sandbox Code Playgroud)
但是,我的项目使用maven-shade-plugin.如果我将代码打包到超级jar中,则上述条件不正确:
mvn package
java -jar /path/to/my.jar
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我观察到只有9 unmarshallers已加载(这些opensaml-core,而不是那些在opensaml-saml-impl然而,当我看的输出.mvn package我可以看到,类型都包含在阴影罐子:
[INFO] Including org.opensaml:opensaml-saml-impl:jar:3.2.0 in the shaded jar.
[INFO] Including org.opensaml:opensaml-profile-api:jar:3.2.0 in the shaded jar.
[INFO] Including org.opensaml:opensaml-messaging-api:jar:3.2.0 in the shaded jar.
[INFO] Including org.opensaml:opensaml-saml-api:jar:3.2.0 in the shaded jar.
[INFO] Including org.opensaml:opensaml-xmlsec-api:jar:3.2.0 in the shaded jar.
[INFO] Including …Run Code Online (Sandbox Code Playgroud) 为了拥有一个可执行jar,我包含了maven依赖项.一切正常,但是jasperreports_extension.properties.Jasper已经有一个替换我的默认值.
我想知道如何将两个文件(默认文件和自定义文件)组合到jar文件中.实际上我手动组合了两个设置,现在我想找到替换程序集插件复制的文件的方法,我已经合并了.
这是我当前的maven程序集插件设置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<archive>
<manifest>
<mainClass>
com.test.sample.MainClass
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
这些是我在报告中添加一些字体的自定义设置:
net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.ireportfamily1453367638844=fonts/fontsfamily1453367638844.xml
Run Code Online (Sandbox Code Playgroud)
和依赖:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.2.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
编辑:
考虑依赖性:
jasperreports_extension.properties 在里面(根级)
jasperreports-6.2.0.jarjasperreports_extension.properties在里面(根级)
jasperreports-fonts-6.0.0.jar(这只是一个测试依赖项)在我用一个阴影替换了程序集插件之后,我报告的初始问题是固定的,但是我得到了这个新问题:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry org/bouncycastle/mail/smime/SMIMEEnvelopedGenerator$EnvelopedGenerator.class
at sun.security.util.SignatureFileVerifier.verifySection(Unknown Source)
at sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已经被问了很多次,但我尝试了一些建议,但仍然收到此错误。
我按如下方式运行 jar:
java -jar MyJar-1.0.jar com.me.ldap.ActiveMain,
我的 ActiveMain.java 文件如下所示:
包 com.me.ldap;
public class ActiveMain {
public static void main(String[] args) throws Exception {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我也简单地尝试java -jar MyJar-1.0.jar过同样的Error: Could not find or load main class错误。我还研究了类路径选项,但我认为这不适用。
我在 Intellij 中将其创建为 Maven 项目。Maven> Lifecycle> package.