手上有个项目需要以jar方式运行,使用maven-shade-plugin插件构建成功后,在服务器上运行"nohup java -jar myProject.jar > /dev/null &"出错,错误信息:“Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”,网上搜索了半天,发现一个解决办法:  http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar


在pom文件maven-shade-plugin插件的配置信息中添加:



<configuration>

    <filters>

        <filter>

            <artifact>*:*</artifact>

            <excludes>

                <exclude>META-INF/*.SF</exclude>

                <exclude>META-INF/*.DSA</exclude>

                <exclude>META-INF/*.RSA</exclude>

            </excludes>

        </filter>

    </filters>

    <!-- Additional configuration. -->

</configuration>

继续运行,之前的错误解决了,却提示新的错误:“Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context] Offending resource: class path resource [applicationContext.xml]”


解决办法是在构建的时候加入META-INF/spring.schemas 和 META-INF/spring.handlers transformers,最终的maven-shade-plugin插件信息配置如下:


<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-shade-plugin</artifactId>

<version> 1.7.1</version>

<executions>

<execution> 

<phase>package</phase>

<goals>

<goal>shade</goal>

</goals>

<configuration>

<filters>

        <filter>

            <artifact>*:*</artifact>

            <excludes>

                <exclude>META-INF/*.SF</exclude>

                <exclude>META-INF/*.DSA</exclude>

                <exclude>META-INF/*.RSA</exclude>

            </excludes>

        </filter>

    </filters>

<transformers>

<transformer

implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">

<resource>META-INF/spring.handlers</resource>

</transformer>

<transformer

implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">

<resource>META-INF/spring.schemas</resource>

</transformer>

<transformer

implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

<mainClass>com.zhilin.paopao.server.NIOServer</mainClass>

</transformer>

</transformers>

</configuration>

</execution>

</executions>

</plugin>


重新clean install打包,再次运行之后问题解决~