Search code examples
mavenclasspathmanifestmaven-assembly-pluginmaven-shade-plugin

How to set manifest class-path in maven shade plugin?


I'm using shade plugin and everything works fine except for being able to set Class-Path for manifest via

 <transformer 
        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
        <mainClass>com.generic.App</mainClass>  
        <classPath>. ./config</classPath>                           
    </transformer>

I get

 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default)              on project SpringThing: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.1:shade for parameter transformer: Cannot find setter, adder nor field in org.apache.maven.plugins.shade.resource.ManifestResourceTransformer for 'classPath' -> [Help 1]

Looking at the doc

http://maven.apache.org/plugins/maven-shade-plugin/apidocs/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.html

Should be able to parse any valid manifest resource? I tried clss-path Class-Path ClassPath nothing works...

I need the classpath to set location of external app property files.

I'm using shade plugin instead of assembly because of a well known problem:

http://blog.idm.fr/2009/09/maven-assembly-plugin-and-spring-namespace-handlers.html

I can do this in assembly pretty easily by the way: (and it works)

 <manifestEntries>
  <Class-Path>. ./config</Class-Path>
 </manifestEntries>

I can't use oneJar plugin via maven because you can't set manifest entries either. (I don't think?)

Any ideas?


Solution

  • Try this and it should work with maven-shade-plugin version 2.1:

    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
     <manifestEntries>
      <Main-Class>your.main.class</Main-Class>
      <Class-Path>your/class/path/here</Class-Path>
     </manifestEntries>
    </transformer>
    

    Mark the difference in tag <Class-Path> as you had <classPath>