Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 700
niken Avatar asked Jun 21 '13 19:06

niken


People also ask

Does Maven add to classpath?

Maven Archiver can add the classpath of your project to the manifest.

How classpath is defined in POM XML?

But, if you must, you can use the additionalClasspathElements element to add custom resources/jars to your classpath. This will be treated as an absolute file system path, so you may want use ${basedir} or another property combined with a relative path.

What is classpath in Maven?

Maven creates this classpath by considering the project's dependencies. The reported classpath consists of references to JAR files cached in local Maven repository. Even the JAR artifact of the project is referenced from local Maven cache and not from the /target directory one or the other might expect.


1 Answers

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>

like image 113
tomasz_kusmierczyk Avatar answered Oct 05 '22 22:10

tomasz_kusmierczyk