Have added multiple main classes in jar using following code in pom.xml as follows
<groupId>com.test</groupId>
<artifactId>indexer</artifactId>
<version>1.0.0-SNAPSHOT</version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<id>build-first</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test1</mainClass>
</transformer>
</transformers>
<finalName>first-runnable</finalName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<id>build-second</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test2</mainClass>
</transformer>
</transformers>
<finalName>second-runnable</finalName>
</configuration>
</execution>
</executions>
</plugin>
But unable to run the jar file successfully from command line. Tried using the command line as
java -jar indexer-1.0.0-SNAPSHOT.jar com.test1
but get no main manifest attribute, in indexer-1.0.0-SNAPSHOT.jar
Could anyone please guide how to run the main classes from commandline using this jar.
Thanks
You should run produced artifact (first-runnable, second-runnable) instead of original one. If you use 'finalName' tag then original artifact will not be modified and new jar will be created as described in plugin documentation
Run
or