The maven dependencies are not added to the jar in eclipse











up vote
0
down vote

favorite
1












I'm coding a maven project with eclipse 2018.09 under java 11 and I've a problem with the maven jar creation. When I clean package the project, it delivers me a jar but no dependencies are added into and i sometimes have warning in eclipse like:



classpath entry junit(for example) will not be exported it may result a ClassNotFoundException.



Which is in fact what's happening when i launch my jar project.



Thanks.










share|improve this question






















  • this may help: stackoverflow.com/questions/1729054/…
    – mangusta
    Nov 10 at 16:56






  • 1




    do share the details of how you are building the project and what all dependencies are you including in the project. what is the exact stacktrace of your exception?
    – nullpointer
    Nov 10 at 16:56










  • the error is about spring but it does so with all the dependencies when i launch the jar an the exact exception i ClassDefNotFoundException in the jar.
    – R.LM
    Nov 10 at 16:58










  • JUnit should never be in a final jar file cause it's only used on classpath for unit tests but never in production code...Please post full pom file and show the full error message...
    – khmarbaise
    Nov 10 at 17:27












  • Yeah i know but it was for the example
    – R.LM
    Nov 10 at 17:28















up vote
0
down vote

favorite
1












I'm coding a maven project with eclipse 2018.09 under java 11 and I've a problem with the maven jar creation. When I clean package the project, it delivers me a jar but no dependencies are added into and i sometimes have warning in eclipse like:



classpath entry junit(for example) will not be exported it may result a ClassNotFoundException.



Which is in fact what's happening when i launch my jar project.



Thanks.










share|improve this question






















  • this may help: stackoverflow.com/questions/1729054/…
    – mangusta
    Nov 10 at 16:56






  • 1




    do share the details of how you are building the project and what all dependencies are you including in the project. what is the exact stacktrace of your exception?
    – nullpointer
    Nov 10 at 16:56










  • the error is about spring but it does so with all the dependencies when i launch the jar an the exact exception i ClassDefNotFoundException in the jar.
    – R.LM
    Nov 10 at 16:58










  • JUnit should never be in a final jar file cause it's only used on classpath for unit tests but never in production code...Please post full pom file and show the full error message...
    – khmarbaise
    Nov 10 at 17:27












  • Yeah i know but it was for the example
    – R.LM
    Nov 10 at 17:28













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I'm coding a maven project with eclipse 2018.09 under java 11 and I've a problem with the maven jar creation. When I clean package the project, it delivers me a jar but no dependencies are added into and i sometimes have warning in eclipse like:



classpath entry junit(for example) will not be exported it may result a ClassNotFoundException.



Which is in fact what's happening when i launch my jar project.



Thanks.










share|improve this question













I'm coding a maven project with eclipse 2018.09 under java 11 and I've a problem with the maven jar creation. When I clean package the project, it delivers me a jar but no dependencies are added into and i sometimes have warning in eclipse like:



classpath entry junit(for example) will not be exported it may result a ClassNotFoundException.



Which is in fact what's happening when i launch my jar project.



Thanks.







java eclipse maven






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 16:53









R.LM

517




517












  • this may help: stackoverflow.com/questions/1729054/…
    – mangusta
    Nov 10 at 16:56






  • 1




    do share the details of how you are building the project and what all dependencies are you including in the project. what is the exact stacktrace of your exception?
    – nullpointer
    Nov 10 at 16:56










  • the error is about spring but it does so with all the dependencies when i launch the jar an the exact exception i ClassDefNotFoundException in the jar.
    – R.LM
    Nov 10 at 16:58










  • JUnit should never be in a final jar file cause it's only used on classpath for unit tests but never in production code...Please post full pom file and show the full error message...
    – khmarbaise
    Nov 10 at 17:27












  • Yeah i know but it was for the example
    – R.LM
    Nov 10 at 17:28


















  • this may help: stackoverflow.com/questions/1729054/…
    – mangusta
    Nov 10 at 16:56






  • 1




    do share the details of how you are building the project and what all dependencies are you including in the project. what is the exact stacktrace of your exception?
    – nullpointer
    Nov 10 at 16:56










  • the error is about spring but it does so with all the dependencies when i launch the jar an the exact exception i ClassDefNotFoundException in the jar.
    – R.LM
    Nov 10 at 16:58










  • JUnit should never be in a final jar file cause it's only used on classpath for unit tests but never in production code...Please post full pom file and show the full error message...
    – khmarbaise
    Nov 10 at 17:27












  • Yeah i know but it was for the example
    – R.LM
    Nov 10 at 17:28
















this may help: stackoverflow.com/questions/1729054/…
– mangusta
Nov 10 at 16:56




this may help: stackoverflow.com/questions/1729054/…
– mangusta
Nov 10 at 16:56




1




1




do share the details of how you are building the project and what all dependencies are you including in the project. what is the exact stacktrace of your exception?
– nullpointer
Nov 10 at 16:56




do share the details of how you are building the project and what all dependencies are you including in the project. what is the exact stacktrace of your exception?
– nullpointer
Nov 10 at 16:56












the error is about spring but it does so with all the dependencies when i launch the jar an the exact exception i ClassDefNotFoundException in the jar.
– R.LM
Nov 10 at 16:58




the error is about spring but it does so with all the dependencies when i launch the jar an the exact exception i ClassDefNotFoundException in the jar.
– R.LM
Nov 10 at 16:58












JUnit should never be in a final jar file cause it's only used on classpath for unit tests but never in production code...Please post full pom file and show the full error message...
– khmarbaise
Nov 10 at 17:27






JUnit should never be in a final jar file cause it's only used on classpath for unit tests but never in production code...Please post full pom file and show the full error message...
– khmarbaise
Nov 10 at 17:27














Yeah i know but it was for the example
– R.LM
Nov 10 at 17:28




Yeah i know but it was for the example
– R.LM
Nov 10 at 17:28












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted











it delivers me a jar but no dependencies are added into [it]




it is totally normal. By default, when Maven builds a jar, it does not add any dependencies in it, but only the .class and resources of your current project.



When you run your programm you want it to find your dependencies otherwise you will face ClassNotFoundException. So you must configure your classpath to reference the dependencies.



1- if you want to run you programm from your local computer with Maven, use the exec Maven plugin with the <java> goal defined in your pom like explained here: https://www.mojohaus.org/exec-maven-plugin/usage.html#Java_goal



alternatively you can run it from a launcher in your IDE. The IDE will build the classpath for you and the classpath will corectly contain your dependencies.



2- if you want to run from the command line on any computer, you have to copy all of you dependencies in one directory (using Maven's dependency plugin mvn dependency:copy) and run you jar like this:



java -cp myProgram.jar:dependencyDirectory/* com.blabla.MainClass



(beware the use of ';' or ':' and '/' or '' depending on Linux/Windows)



3- as an alternative you can run your jar with java -jar myprogram.jar but only if it contains a correct MANIFEST.MF where the location of all the dependencies are hardcoded.



My advice is to target solution 1 or 2 first.



PS: you can also create "fat jars" or "uber jars" containing your dependencies but I would advise you do not target this solution at first.






share|improve this answer





















  • did it solve your problem ? If so can you mark it as solved ? Thanks
    – Francois Marot
    Nov 11 at 16:12


















up vote
0
down vote













You can simply add this to your pom.xml (under the < plugins > tag):



        <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>


Remember to change the mainclass to your entrypoint (which class the static void main(string[args]) is).
Now when you run the command mvn clean install there will be a jar in the targets folder with name yourproject-version-SNAPSHOT-jar-with-dependencies.jar






share|improve this answer





















  • what about shade plugin?
    – Bernard
    Nov 11 at 11:34











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241216%2fthe-maven-dependencies-are-not-added-to-the-jar-in-eclipse%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted











it delivers me a jar but no dependencies are added into [it]




it is totally normal. By default, when Maven builds a jar, it does not add any dependencies in it, but only the .class and resources of your current project.



When you run your programm you want it to find your dependencies otherwise you will face ClassNotFoundException. So you must configure your classpath to reference the dependencies.



1- if you want to run you programm from your local computer with Maven, use the exec Maven plugin with the <java> goal defined in your pom like explained here: https://www.mojohaus.org/exec-maven-plugin/usage.html#Java_goal



alternatively you can run it from a launcher in your IDE. The IDE will build the classpath for you and the classpath will corectly contain your dependencies.



2- if you want to run from the command line on any computer, you have to copy all of you dependencies in one directory (using Maven's dependency plugin mvn dependency:copy) and run you jar like this:



java -cp myProgram.jar:dependencyDirectory/* com.blabla.MainClass



(beware the use of ';' or ':' and '/' or '' depending on Linux/Windows)



3- as an alternative you can run your jar with java -jar myprogram.jar but only if it contains a correct MANIFEST.MF where the location of all the dependencies are hardcoded.



My advice is to target solution 1 or 2 first.



PS: you can also create "fat jars" or "uber jars" containing your dependencies but I would advise you do not target this solution at first.






share|improve this answer





















  • did it solve your problem ? If so can you mark it as solved ? Thanks
    – Francois Marot
    Nov 11 at 16:12















up vote
1
down vote



accepted











it delivers me a jar but no dependencies are added into [it]




it is totally normal. By default, when Maven builds a jar, it does not add any dependencies in it, but only the .class and resources of your current project.



When you run your programm you want it to find your dependencies otherwise you will face ClassNotFoundException. So you must configure your classpath to reference the dependencies.



1- if you want to run you programm from your local computer with Maven, use the exec Maven plugin with the <java> goal defined in your pom like explained here: https://www.mojohaus.org/exec-maven-plugin/usage.html#Java_goal



alternatively you can run it from a launcher in your IDE. The IDE will build the classpath for you and the classpath will corectly contain your dependencies.



2- if you want to run from the command line on any computer, you have to copy all of you dependencies in one directory (using Maven's dependency plugin mvn dependency:copy) and run you jar like this:



java -cp myProgram.jar:dependencyDirectory/* com.blabla.MainClass



(beware the use of ';' or ':' and '/' or '' depending on Linux/Windows)



3- as an alternative you can run your jar with java -jar myprogram.jar but only if it contains a correct MANIFEST.MF where the location of all the dependencies are hardcoded.



My advice is to target solution 1 or 2 first.



PS: you can also create "fat jars" or "uber jars" containing your dependencies but I would advise you do not target this solution at first.






share|improve this answer





















  • did it solve your problem ? If so can you mark it as solved ? Thanks
    – Francois Marot
    Nov 11 at 16:12













up vote
1
down vote



accepted







up vote
1
down vote



accepted







it delivers me a jar but no dependencies are added into [it]




it is totally normal. By default, when Maven builds a jar, it does not add any dependencies in it, but only the .class and resources of your current project.



When you run your programm you want it to find your dependencies otherwise you will face ClassNotFoundException. So you must configure your classpath to reference the dependencies.



1- if you want to run you programm from your local computer with Maven, use the exec Maven plugin with the <java> goal defined in your pom like explained here: https://www.mojohaus.org/exec-maven-plugin/usage.html#Java_goal



alternatively you can run it from a launcher in your IDE. The IDE will build the classpath for you and the classpath will corectly contain your dependencies.



2- if you want to run from the command line on any computer, you have to copy all of you dependencies in one directory (using Maven's dependency plugin mvn dependency:copy) and run you jar like this:



java -cp myProgram.jar:dependencyDirectory/* com.blabla.MainClass



(beware the use of ';' or ':' and '/' or '' depending on Linux/Windows)



3- as an alternative you can run your jar with java -jar myprogram.jar but only if it contains a correct MANIFEST.MF where the location of all the dependencies are hardcoded.



My advice is to target solution 1 or 2 first.



PS: you can also create "fat jars" or "uber jars" containing your dependencies but I would advise you do not target this solution at first.






share|improve this answer













it delivers me a jar but no dependencies are added into [it]




it is totally normal. By default, when Maven builds a jar, it does not add any dependencies in it, but only the .class and resources of your current project.



When you run your programm you want it to find your dependencies otherwise you will face ClassNotFoundException. So you must configure your classpath to reference the dependencies.



1- if you want to run you programm from your local computer with Maven, use the exec Maven plugin with the <java> goal defined in your pom like explained here: https://www.mojohaus.org/exec-maven-plugin/usage.html#Java_goal



alternatively you can run it from a launcher in your IDE. The IDE will build the classpath for you and the classpath will corectly contain your dependencies.



2- if you want to run from the command line on any computer, you have to copy all of you dependencies in one directory (using Maven's dependency plugin mvn dependency:copy) and run you jar like this:



java -cp myProgram.jar:dependencyDirectory/* com.blabla.MainClass



(beware the use of ';' or ':' and '/' or '' depending on Linux/Windows)



3- as an alternative you can run your jar with java -jar myprogram.jar but only if it contains a correct MANIFEST.MF where the location of all the dependencies are hardcoded.



My advice is to target solution 1 or 2 first.



PS: you can also create "fat jars" or "uber jars" containing your dependencies but I would advise you do not target this solution at first.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 23:54









Francois Marot

507213




507213












  • did it solve your problem ? If so can you mark it as solved ? Thanks
    – Francois Marot
    Nov 11 at 16:12


















  • did it solve your problem ? If so can you mark it as solved ? Thanks
    – Francois Marot
    Nov 11 at 16:12
















did it solve your problem ? If so can you mark it as solved ? Thanks
– Francois Marot
Nov 11 at 16:12




did it solve your problem ? If so can you mark it as solved ? Thanks
– Francois Marot
Nov 11 at 16:12












up vote
0
down vote













You can simply add this to your pom.xml (under the < plugins > tag):



        <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>


Remember to change the mainclass to your entrypoint (which class the static void main(string[args]) is).
Now when you run the command mvn clean install there will be a jar in the targets folder with name yourproject-version-SNAPSHOT-jar-with-dependencies.jar






share|improve this answer





















  • what about shade plugin?
    – Bernard
    Nov 11 at 11:34















up vote
0
down vote













You can simply add this to your pom.xml (under the < plugins > tag):



        <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>


Remember to change the mainclass to your entrypoint (which class the static void main(string[args]) is).
Now when you run the command mvn clean install there will be a jar in the targets folder with name yourproject-version-SNAPSHOT-jar-with-dependencies.jar






share|improve this answer





















  • what about shade plugin?
    – Bernard
    Nov 11 at 11:34













up vote
0
down vote










up vote
0
down vote









You can simply add this to your pom.xml (under the < plugins > tag):



        <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>


Remember to change the mainclass to your entrypoint (which class the static void main(string[args]) is).
Now when you run the command mvn clean install there will be a jar in the targets folder with name yourproject-version-SNAPSHOT-jar-with-dependencies.jar






share|improve this answer












You can simply add this to your pom.xml (under the < plugins > tag):



        <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>


Remember to change the mainclass to your entrypoint (which class the static void main(string[args]) is).
Now when you run the command mvn clean install there will be a jar in the targets folder with name yourproject-version-SNAPSHOT-jar-with-dependencies.jar







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 11:28









Mr.Turtle

7892824




7892824












  • what about shade plugin?
    – Bernard
    Nov 11 at 11:34


















  • what about shade plugin?
    – Bernard
    Nov 11 at 11:34
















what about shade plugin?
– Bernard
Nov 11 at 11:34




what about shade plugin?
– Bernard
Nov 11 at 11:34


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241216%2fthe-maven-dependencies-are-not-added-to-the-jar-in-eclipse%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation