2011-11-28 45 views
12

我有以下异常:在线程Maven的遮阳罐子抛出异常

异常“主要” java.lang.SecurityException异常:无manifiest 部分签署文件条目 的javax /安全/证书/ CertificateException.class 在sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:380) 在sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:231) 在sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier。 java:176) at java.util.jar.JarVerifier.processEntry(JarVerifier.java:288)012 (JarVerifier.java:199) at java.util.jar.JarFile.initializeVerifier(JarFile.java:323) at java.util.jar.JarFile.getInputStream(JarFile。 java:388) at sun.misc.URLClassPath $ JarLoader $ 2.getInputStream(URLClassPath.java:692) at sun.misc.Resource.cachedInputStream(Resource.java:61) at sun.misc.Resource.getByteBuffer(Resource .java:144) at java.net.URLClassLoader.defineClass(URLClassLoader.java:256) at java.net.URLClassLoader.access $ 000(URLClassLoader.java:58) at java.net.URLClassLoader $ 1.run(URLClassLoader .java:197) at java.net.URLClas上的java.security.AccessController.doPrivileged(Native Method) sLoader.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> 

回答

1

的问题是因为Java版本。 我没有注意到我的新ide自动使用ibm的java,当我将jre更改为sun的java时,它效果不错:)

0

堆栈跟踪的最后一行上面说

找不到主类:com.mainClass。

也许在调用插件之前没有编译类名或类中的拼写错误?

+0

对不起,我不认为这是名称的问题。或者它应该给noclassdeffoundexception一个例外。 –

26

SecurityException出现是因为你的一个依赖是一个签名的jar。 由于阴影插件重新包装这个罐子,它变得无效。 - >SecurityException发布时

要解决此问题,您必须未签名依赖关系jar包,同时重新打包它们。 这可以通过简单地重新包装不使签署的jar文件,使用过滤器来完成:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <version>1.5</version> 
    <executions> 
     <execution> 
      <id>stand-alone</id> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <shadedArtifactAttached>true</shadedArtifactAttached> 
       <shadedClassifierName>stand-alone</shadedClassifierName> 
       <filters> 
        <filter> 
         <!-- 
          Exclude files that sign a jar 
          (one or multiple of the dependencies). 
          One may not repack a signed jar without 
          this, or you will get a 
          SecurityException at program start. 
         --> 
         <artifact>*:*</artifact> 
         <excludes> 
          <exclude>META-INF/*.SF</exclude> 
          <exclude>META-INF/*.RSA</exclude> 
          <exclude>META-INF/*.INF</exclude> <!-- This one may not be required --> 
         </excludes> 
        </filter> 
       </filters> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

这种溶液从这里提取: http://jira.codehaus.org/browse/MSHADE-61