Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Running several main-classes from the same JAR file

Thread view: 
eli.hen@gmail.com - 18 Dec 2005 11:11 GMT
Hi,

I want to run 2 different main-classes from the same JAR. Is it
possible? How?

The point is that both main-classes use the same common classes, so it
seems better that all classes will reside in the same 1 JAR file.

-thanks, Eli
Thomas Kellerer - 18 Dec 2005 11:13 GMT
java -cp yourjar.jar package.Main1

java -cp yourjar.jar package.Main2

Read the docs for the java command, it's all explained there :)

Thomas

eli.hen@gmail.com wrote on 18.12.2005 12:11:
> Hi,
>
[quoted text clipped - 5 lines]
>
> -thanks, Eli
Thomas Hawtin - 18 Dec 2005 12:06 GMT
> I want to run 2 different main-classes from the same JAR. Is it
> possible? How?
>
> The point is that both main-classes use the same common classes, so it
> seems better that all classes will reside in the same 1 JAR file.

How are you expecting to select between the two? If you can set the
command line then, as Thomas Kellere suggested, put the jars on the
class-path and use the execute a class form of the java command.
Alternatively, add a new class as the main-class that determines which
of the other classes to run.

However, I'd suggest it is not normally worthwhile. You might as well
just have two smaller jar files. If you don't want duplication, you can
add to the class-path through the manifest.

http://java.sun.com/docs/books/tutorial/jar/manifest/downman.html

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Andrew Thompson - 18 Dec 2005 13:09 GMT
> I want to run 2 different main-classes from the same JAR. Is it
> possible?

Sure, you can do that, but[1]

> ..How?

One way is as described ny Thomsa Kellerer, to
launch two different mains from the one Jar by
invoking the class from the command line.

Another, more user-friendly way to deploy the
applications is using Webstart/JWS, which would simply
require you to specify a different main in each JNLP
descriptor.

*Note the jar file/s for JWS would need to be signed if
you intend the application/s to gain the 'full priviliges'
usually given to an app. launched from the command line.*

> The point is that both main-classes use the same common classes,

[1] ..but, as Thomas Hawtin suggested, it may
not make sense to deploy the mains and core classes
in the same jar.  Instead consider breaking it into
the 'common library' jar, with each main class and
it's own unique classes in a second (third, fourth..)
jar.

Webstart/JWS can handle that as well, and will only
deliver the library application once, even if it is
used for 10 different applications (or Webstarted
applets).

>..so it
> seems better that all classes will reside in the same 1 JAR file.

Not with the JWS option..

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew

Andrew Thompson - 18 Dec 2005 13:17 GMT
> One way is as described ny Thomsa Kellerer, ..

Thomas, ..Thomas.  (silly me)

<weak defence>
If only I could have 'replied' to both posts at once.
</weak defence>

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.