A
A
Andrey Yanduganov2017-08-13 13:58:57
Java
Andrey Yanduganov, 2017-08-13 13:58:57

How to build jar using maven?

I'm trying to compile a project using maven.
When I run the resulting jar file, I get an error:

Error: Could not find or load main class <путь до файла>

Tried different maven plugins. I tried all the ways from here: www.baeldung.com/executable-jar-with-maven
If you manually specify the class to be launched when starting the jar, then everything works.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Yanduganov, 2017-08-15
@andreybotanic

Understood the problem.
It turned out that I'm just not trying to run the finished jar correctly. Instead of " java -jar file.jar " I wrote " java file.jar "

A
Andrey K, 2017-08-14
@Ksenobait_15

most likely the problem is here

<mainClass>
         org.baeldung.executable.ExecutableMavenJar
</mainClass>

here you need to specify the path to your class with the main method.
if not, then you need a sample code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question