FatJar with external dependencies?

1,230 views
Skip to first unread message

Stephan Wissel

unread,
Mar 21, 2016, 1:45:21 PM3/21/16
to vert.x
I'm trying to switch from launching my verticle from vertx to fatjar. I have:

#!/bin/sh
DOMINO_HOME=/opt/ibm/domino/notes/latest/linux
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export VERTX_HOME=/usr/lib/node_modules/vertx3-full/vertx
export DYLD_LIBRARY_PATH=$DOMINO_HOME
export LD_LIBRARY_PATH=$DOMINO_HOME
export V_PATH=/home/domino/scripts
export CLASSPATH=.:$V_PATH/*:$DOMINO_HOME/jvm/lib/ext/Notes.jar:$CLASSPATH
vertx start com.ibm.issc.castle.CastleDominoLoader --vertx-id domino --redirect-output > /home/domino/logs/vertx.log 2>&1


Works like a charm --- with all dependend jars in $V_Path short of the Notes.jar (which belongs to the installation)
When I switch to:


#!/bin/sh
DOMINO_HOME=/opt/ibm/domino/notes/latest/linux
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export VERTX_HOME=/usr/lib/node_modules/vertx3-full/vertx
export DYLD_LIBRARY_PATH=$DOMINO_HOME
export LD_LIBRARY_PATH=$DOMINO_HOME
export V_PATH=/home/domino/scripts
export CLASSPATH=.:$V_PATH/*:$DOMINO_HOME/jvm/lib/ext/Notes.jar:$CLASSPATH
java -jar ./castle-domino-complete.jar start --vertx-id domino --redirect-output > /home/domino/logs/vertx.log 2>&1


I get class not found errors for my Notes classes (which I can't add to the FatJar for some reasons). What do I miss to make the FatJar recognize the external classpath?

Asher Tarnopolski

unread,
Mar 22, 2016, 4:58:56 AM3/22/16
to vert.x
try to add Class-Path attribute to your fatjar's manifest.

Alexander Lehmann

unread,
Mar 22, 2016, 8:20:08 AM3/22/16
to vert.x
java -jar does not support adding classes in the CLASSPATH, I think you have to put the fatjar into your classpath and run the main class.

Tim Fox

unread,
Mar 22, 2016, 8:27:55 AM3/22/16
to ve...@googlegroups.com
That shouldn't be necessary. Although java -jar doesn't support adding entries from classpath, the Vert.x launcher (or the old starter) will parse -cp itself. So adding -cp on the command line should be sufficient.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/228f9010-f31e-4ff5-a03f-e6a221c0cfa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephan Wissel

unread,
Mar 22, 2016, 4:14:48 PM3/22/16
to vert.x
I tried various options, this works:

vertx start com.ibm.issc.castle.CastleDominoLoader --vertx-id domino --redirect-output > /home/domino/logs/vertx.log 2>&1

java com.ibm.issc.castle.CastleDominoLoader --vertx-id domino --redirect-output > /Users/stw/Code/castle/castle-backend-java/logs/vertx.log 2>&1

the later with the CLASSPATH set like before

This didn't work:

java -jar castle-domino-complete.jar -cp $DOMINO_HOME/jvm/lib/ext/Notes.jar --vertx-id domino --redirect-output > /home/domino/logs/vertx.log 2>&1

I also tried the -cp before the -jar. The error was different. I'll stick with the vertx launcher. Thx everybody for chipping in

Tim Fox

unread,
Mar 23, 2016, 4:25:52 AM3/23/16
to ve...@googlegroups.com
-cp should certainly work with the launcher.

If it doesn't please file an issue as that would be a bug.

Stephan Wissel

unread,
Mar 23, 2016, 7:36:15 AM3/23/16
to vert.x
Hi Tim,

just to make sure I didn't mess up :-). In my POM I configured the FatJAR like this:

        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>io.vertx.core.Starter</Main-Class>
                                        <Main-Verticle>${exec.mainClass}</Main-Verticle>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                            <artifactSet />
                            <outputFile>${project.build.directory}/${finalName}-fat.jar</outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>



Using io.vertx.core.Starter to start. If that looks OK, I'll file a bug

Clement Escoffier

unread,
Mar 24, 2016, 3:15:53 AM3/24/16
to ve...@googlegroups.com
Hi,

You should use Launcher, not Starter in your fat jar.

Then, to add dependencies, just use -cp my-dependency.jar:my-second-dependency.jar:./cluster.xml 

Clement 


Navrang Shekhawat

unread,
Jun 6, 2018, 8:39:16 AM6/6/18
to vert.x
Hi,

I am also facing the similar issue with external jar files to be loaded in class path when we run vertx fat jar from command line.
As suggested i am using a class VerticleLauncher which extends Launcher to deploy the verticles. But i am unable to figure how to do.

In the group sugegsted by Clement that "to add dependencies, just use -cp my-dependency.jar:my-second-dependency.jar:./cluster.xml " what exactly this means when we run the fat jar from command line or we need to add these entries in MANIFEST file. Please suggest.

Thanka
Navrang Shekhawat

Oren Shvalb

unread,
Jun 6, 2018, 11:03:30 PM6/6/18
to vert.x
I have a problem running fatjar with logback.xml as external dependency.
I the maven-shade-plugin I exclude logback.xml so the jar doesn't contain it, and when I put it in my production machine I have an external logback.xml file.

I run it as follow:

java -jar game-deployer.jar --conf config.json -cluster -cp . 

and the logback.xml is at the same folder a long with the jar file.

btw, if I don't exclude logback.xml then it works fine.

any idea?

Clement Escoffier

unread,
Jun 7, 2018, 2:14:04 AM6/7/18
to ve...@googlegroups.com
Hi,

For logback, it’s generally better to indicate the location of the file with: -Dlogback.configurationFile=/path/to/logback.xml.

java -Dlogback.configurationFile=/path/to/logback.xml -jar game-deployer.jar …

Clement

-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

Asher Tarnopolski

unread,
Jun 7, 2018, 3:19:11 AM6/7/18
to vert.x
oren,

you can try to add the folder with your file to the classpath like this:

java -Xbootclasspath/a:/home/user/blabla
or
java -Xbootclasspath/a:C:/Users/Blabla on windows

Navrang Shekhawat

unread,
Jun 7, 2018, 1:34:28 PM6/7/18
to vert.x
Hi,

As mentioned in my previous post i am facing issues while running fat jar from command line, i am having external jars from apache cxf and jar for endpointoperations(client code to call end point on different systems). These jars should be loaded externally and they should not be the part of fat jar.
Please suggest how to proceed with this scenario as i am stuck and not able to progress.

Thanks

Oren Shvalb

unread,
Jun 7, 2018, 9:31:34 PM6/7/18
to vert.x
Thanks, it works great!

Oren Shvalb

unread,
Jun 7, 2018, 9:32:35 PM6/7/18
to vert.x
Thanks Asher,
I ended up using ' -Dlogback.configurationFile=/path/to/logback.xml'

Cheers,
Oren
Reply all
Reply to author
Forward
0 new messages