apache camel - packaging an executable jar
Asked Answered
M

2

3

I'm using maven for building my jar (Intellij IDEA IDE). It is app built using Apache Camel. An excerpt from my pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>MainDriver</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

I'm able to retrieve a jar file from maven but upon running all I got are the NoClassDeFFound errors.

Finally, I've tried using the one-jar plugin (http://one-jar.sourceforge.net/‎) . And I've got it working. My question is can I achieve the same without using one-jar? I'm not liking the packaging of one-jar, what it does is when you extract the jar from one-jar, you will find your app jar within it, so you'll need to do an extra extraction on your jar to get to your classes/resources. My configuration files are on resources and from time to time, I'll be needing to modify it.

Thanks!

Melvinamelvyn answered 22/1, 2014 at 4:25 Comment(1)
One-jar plugin is nice to avoid appending stuff to be specified in the shade plugin, like in Ralf answer (which is good btw). I would anyway consider making these configuration files totally externalized, and not using resources in the classpath. Camel properties can be specified from various protocols and locations, just like Spring ones.Callender
S
8

The maven-shade-plugin creates a jar with your application code and all dependencies merged into a single jar file. The problem with this approach is that you need to decided what to do with files with conflicting names. This is the configuration we use to build executable JARs for our Camel apps, including Spring and all required dependencies.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>org.apache.camel.spring.Main</mainClass>
            </transformer>
            <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.AppendingTransformer">
                <resource>META-INF/spring.tooling</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                <resource>META-INF/cxf/bus-extensions.txt</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
            <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                <resource>META-INF/INDEX.LIST</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                <resource>META-INF/MSFTSIG.SF</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                <resource>META-INF/MSFTSIG.RSA</resource>
            </transformer>
        </transformers>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Seasickness answered 22/1, 2014 at 6:52 Comment(0)
R
0

You can use maven-jar-plugin

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
    <archive>
        <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>com.poc.sms.MainApp</mainClass>
        </manifest>
    </archive>
</configuration>
</plugin>
Raising answered 4/7, 2019 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.