users@glassfish.java.net

Re: Dumb Beginner Question

From: <glassfish_at_javadesktop.org>
Date: Mon, 06 Oct 2008 15:08:00 PDT

The "custom JVM" part I find a bit disturbing. It would be interesting as to what is "custom" about it.

What your command line does is a couple of things.

1) It executes the "default class" of your "company.jar" file. This is defined in the Manifest of the jar as to exactly what class is being executed. But on that class, the "public static void main(String args[])" method is what is being executed.

2) All of those arguments are arguments to the actual executing programs (as in they are passed as string in the args[] array of the main method).

3) I believe this includes the "-classpath" option as well as the "examples.hellowworld.HelloWorldMain" option. "-classpath" is normally used for the JVM itself, but since it appears AFTER the -jar option, I think the JVM is going to ignore that argument and pass it to the program as an option. As far as I know "-jar" and "-classpath" are exclusive options to the JVM, you can have one or the other but not both.

If you wish to use the code in this jar within Glassfish, you should simply treat it as a library. This means you will call the code within the jar directly rather than, typically, relying on the jars default class static "main" method.

Now, you could certainly call that yourself, building up your own argument string array and simply passing it to the "main" method, but most systems aren't used that way.

Unfortunately, for someone new to Java, this is kind of a nasty bit to step in to as it touches a bit on some of the details of how the JVM works beyond simply coding Java. Not a nice place to be for someone new.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=303612