File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Jar - more than 1 main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar - more than 1 main" Watch "Jar - more than 1 main" New topic

Jar - more than 1 main

Lars Christian Hansen

Joined: May 05, 2005
Posts: 9

suppose I have an application with more than 1 main class. I have jar'ed the file and now depending on the situation, wanna be able to call on or the other main class. Is that possible via the command line?

I was thinks something in the lines of(TR.class is one of the main classes):

java -jar AppName.jar TR

But doesn't seem to work


Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

java -classpath AppName.jar TR

[Jess in Action][AskingGoodQuestions]
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 691
The command: java -jar ...
uses the contents of the jar file's manifest Main-class entry. There is only one per jar file.
I agree. Here's the link:
subject: Jar - more than 1 main
It's not a secret anymore!