The maven dependencies are not added to the jar in eclipse
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
java eclipse maven
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
add a comment |
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
add a comment |
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.
did it solve your problem ? If so can you mark it as solved ? Thanks
– Francois Marot
Nov 11 at 16:12
add a comment |
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
what about shade plugin?
– Bernard
Nov 11 at 11:34
add a comment |
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.
did it solve your problem ? If so can you mark it as solved ? Thanks
– Francois Marot
Nov 11 at 16:12
add a comment |
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.
did it solve your problem ? If so can you mark it as solved ? Thanks
– Francois Marot
Nov 11 at 16:12
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
what about shade plugin?
– Bernard
Nov 11 at 11:34
add a comment |
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
what about shade plugin?
– Bernard
Nov 11 at 11:34
add a comment |
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
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
answered Nov 11 at 11:28
Mr.Turtle
7892824
7892824
what about shade plugin?
– Bernard
Nov 11 at 11:34
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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