A
A
Anatoly2016-08-15 11:37:00
Java
Anatoly, 2016-08-15 11:37:00

How to run Main class from Jar?

With the help of maven plugins, I form the following structure of the working directory of the program:
application.jar - application, only classes written by me and generated by me
config.xml - configuration file
lib/ - directory with dependency libraries I run a
class containing a method with a public static signature void main(String[] args) with the following command:

java -classpath application.jar;lib/*.jar;. org.company.application.Launcher

, and in response I get
Error: Could not find or load main class org.company.application.Launcher

That's right, not java -jar application.jar with Main-Class in application.jar/META-INF/MANIFEST.MF because there are several possible entry points for different use cases.
Inside the application.jar file org/company/application/Launcher.class is there.
Where the dog rummaged and how to understand where it rummaged?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zakharov Alexander, 2016-08-15
@AlexZaharow

Try to put a dot before lib (the current directory), otherwise, probably, java does not really understand where lib is after all (well, remove *.jar):

java classpath application.jar; ./lib ;. org.company.application.Launcher

A
Anatoly, 2016-08-17
@TheUralSky

I didn’t find a solution in the existing situation, instead I wrote a single entry point, which, depending on the parameters passed, transfers control to existing mains (subject to refactoring, but so far) and made jar executable with this class as Main-Class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question