Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building JAR that includes all its dependencies

Tags:

java

jar

ant

This is probably a really fundamental question, but I'm afraid I don't know much about Java and I couldn't find the answer anywhere.

I'm attempting to build an Ant library which depends on the TFS SDK. I followed the guide to setting up a project, but when I export it as a JAR and try to run a task using ANT I get the following error:

java.lang.NoClassDefFoundError: /com/microsoft/tfs/core/util/TFSUser

I realise I could put the TFS SDK JAR in my ANT lib folder, but if possible I'd like my JAR to include it and the library just work without having to do so.

This answer seems to say it's possible to include all the resources needed to run using Eclipse (I'm using 3.7.2) but it doesn't detail how to actually do it. What is the option in Eclipse to do so?

like image 941
Greg Beech Avatar asked Mar 15 '12 14:03

Greg Beech


People also ask

Does jar contain all dependencies?

java is a main starting point which has main(String args[]) method inside. pom. xml file in which we will add Maven Plugins which will build executable . jar project with all included dependancies.

Which build plugin allows you to create a fat jar that contains all the dependencies in the final JAR file?

Maven is one of the most used tools for Java application development. Maven packaging will create a Jar file without dependencies. Maven provides other plugins using which we can generate the jar with all its dependencies which is usually called FatJar, which is used as an executable Jar file.

What is a jar with dependencies?

The value jar-with-dependencies tells Maven to build a JAR file with dependencies which is another term for a Fat JAR. The executions XML element tells Maven which Maven build phase and goal this Maven plugin should be executed during. The maven-assembly-plugin should always be executed during the package phase.


1 Answers

Select "Extract required libraries into generated JAR" as you do the export.

Extract required libraries into generated JAR

Select "Extract required libraries into generated JAR" as you do the export.

like image 111
Java42 Avatar answered Nov 03 '22 10:11

Java42