Skip to main content

passing fully qualified class name as command line argument in jws

4 replies [Last post]
pratik2580
Offline
Joined: 2007-04-10
Points: 0

my application has a Loader class which is set as the main class in the jnlp file. Loader class takes the name of a class as a command line argument which it then loads and invokes at run time.

I've included the fully qualified name of the class which i want to load at runtime in the tag of the jnlp file and am including the jar which contains the particular class in section of the jnlp. But inspite of doing this the java web start is unable to launch the application. It is giving a java.lang.ClassNotFoundException for the class whose name i'm sending as a command line argument.

note: To be specific my main class for the purpose of java web start is com.sun.star.lib.loader.
Loader
which is an openoffice.org loader (since my application needs to access openoffice apis.) I'm asking the loader to dynamically load my actual main application class by passing the name of that class as a command line argument. The Loader loads that class and in turn invokes main of that class.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
twalljava
Offline
Joined: 2004-07-26
Points: 0

Is your loader properly configured to defer to the web start class loader, or at least use the same class path? If not, how does your loader know where to find the class?

pratik2580
Offline
Joined: 2007-04-10
Points: 0

I,m giving the class path of the class i want the loader to load by specifying its in the resources section of the jnlp file. Isnt that enough for the loader to know where to find the class??...

What do you exactly mean by defering to the web start class loader??

twalljava
Offline
Joined: 2004-07-26
Points: 0

You implied the class loader you were using was *not* the web start class loader. If so, it will only "defer" to the web start class loader if said loader is provided as the parent class loader when you create the other one.

pratik2580
Offline
Joined: 2007-04-10
Points: 0

> You implied the class loader you were using was *not*
> the web start class loader. If so, it will only
> "defer" to the web start class loader if said loader
> is provided as the parent class loader when you
> create the other one.

are you suggesting that my class loader should either use the web start class loader or somehow extend the web-start class loader ?

If i'm not wrong what you are saying is same as what is given on[u] [b]Java Web Start Frequently Asked Questions[/b][/u] page of SUN site:

[u]Java Web Start uses a user-level classloader to load all the application resources specified in the JNLP file. This classloader implements the security model and the downloading model defined by the JNLP specification. This is no different than how the AppletViewer or the Java Plug-In works.

This has the, unfortunate, side-effect that Class.forName will not find any resources that are defined in the JNLP file. The same is true for looking up resources and classes using the system class loader (ClassLoader.getSystemClassLoader).

To find application resources in Java Web Start, use the classloader that loaded your application, for example use the following call in the in the application;s main thread:

this.getClass().getClassLoader();

You can also use:

Thread.getCurrent().getContextClassLoader();[/u]

I think your suggestion would be helpful!..[i][b]thanks a ton![/b][/i]