我有以下例外:
线程"main"中的异常java.lang.SecurityException:在sun.security的sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:380)中没有签名文件条目javax/security/cert/CertificateException.class的最明显部分. util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:231)位于java.util的java.util.jar.JarVerifier.processEntry(JarVerifier.java:288)的sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176) .jar.JarVerifier.update(JarVerifier.java:199)位于sun的java.util.jar.JarFile.getInputStream(JarFile.java:388)的java.util.jar.JarFile.initializeVerifier(JarFile.java:323). misc.URLClassPath $ JarLoader $ 2.getInputStream(URLClassPath.java:692)位于sun.net的sun.misc.Resource.getByteBuffer(Resource.java:144)的sun.misc.Resource.cachedInputStream(Resource.java:61). URLClassLoader.defineClass(URLClassLoader.java:256)at java.net.URLClassLoader.access $ 000(URLClassLoader.java:58)at java.net.URLClassLoader $ 1.run(URLCl)assLoader.java:197)java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:190)at java.lang.ClassLoader.loadClass(ClassLoader.java:306)at sun .misc.Launcher $ AppClassLoader.loadClass(Launcher.java:301)at java.lang.ClassLoader.loadClass(ClassLoader.java:247)找不到主类:com.mainClass.程序将会退出.
我的pom:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filter>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.mainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud) 我正在使用maven shade插件为我的项目生成一个合并jar.jar是按预期生成的,当我尝试使用jar并运行它时,我得到了一个
java.lang.SecurityException:Manifest主要属性错误的签名文件摘要无效.
我搜索了上面的错误消息,许多人建议从META-INF目录中排除清单签名.因此,我已经包含了从目录中排除这些文件的步骤[我看到两个文件的名称JARSIGN_.RSA和JARSIGN_.SF],但由于一些奇怪的原因,maven shade插件无法从META-INF目录中排除这些文件.谁能解释一下我可能做错了什么?我的pom.xml在下面,我用来生成jar的命令是:
mvn clean package shade:shade
Run Code Online (Sandbox Code Playgroud)
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.xyz</groupId>
<artifactId>myjar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<properties>
<!-- A few custom properties -->
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- Other The dependencies are here -->
</dependencies>
<repositories>
<!-- Repository Information -->
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions> …Run Code Online (Sandbox Code Playgroud) 我想构建项目,以便最终jar包含单个jar文件中的所有依赖项(如果不可能包括从jar文件中的依赖项的类)我跟随线程包含Maven的jar中的依赖项但是包含了依赖项我甚至没有在我的pom中提到过.这是我的POM,只有两个依赖项.
我希望在构建final时,它包含它在pom中提到的特定依赖项(在类或jar形式中)
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>utils</artifactId>
<version>1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)