Skip to main content

Again JAR files...

10 replies [Last post]
Anonymous

To ome back to the multiple JAR file issue:

OK, I can add multiple JAR files in the JNLP file and they are downloaded in the cache directory. When that application starts I get my home directory as current path, but nor the directory where the JAR fiels are cached.

Is there in JNLP a way to specify a path or from the application to find the path were WebStart stored my files?

Thanks,

Patrick

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zander
Offline
Joined: 2003-06-13

> > First each jar file should contain the 'content' file
> > whether .ini, .properties or .xml with exactly the
> > same name and path (within the jar). Suppose we
> > call them all myPlugin.properties and locate them in the
> > root directory of each jar.
>
> OK, I have this.
> > for (Enumeration e=getClassLoader().getResources("/myPlugin.properties"
> Ah ok, the getResources() would load all
> myPlugins.properties in the enumeration.

Naturally the jars should really be downloaded externally from webstart, and loaded in a separate classloader (URLClassLoader comes to mind) to fix this problem correctly...

I wrote such a system some time ago; and can tell you classloaders in Java are quite fun ]:)

mthornton
Offline
Joined: 2003-06-10

>
> Sorry if that was not clear, still trying to improve
> my English ;)

Your English is much better than my German (I did study it once and still have a Germand/English dictionary at hand).

mthornton
Offline
Joined: 2003-06-10

Why do you want to know where the .jar files are? You can obtain anything they might contain using getResourceAsStream. Otherwise try getResource for a item you know should be there and take the front part of the URL that you get.

Anonymous

> Why do you want to know where the .jar files are? You
> can obtain anything they might contain using
> getResourceAsStream. Otherwise try getResource for a
> item you know should be there and take the front part
> of the URL that you get.

Because when the program starts it does not know a) the plugin names b) how many plugins are installed c) and where they are.

Currently if I start the app from console I am reading a special directory called plugins and analyse all .jar files in this directory.

With WebStart I jsut have the resource tag int he .jnlp file. And: One requirement is that the program works as application started fomr console. Second requirement is the WebStart feature, which is not a must to do, but it would be really nice.

Thanks,

Patrick

mthornton
Offline
Joined: 2003-06-10

Add a properties file to each plugin (.jar) all with the same name such as pluginInfo.properties
Then use ClassLoader.getResources to obtain a URL for each such file. Load each properties file in turn to obtain the details for that plugin. It needn't be a properties file --- an xml file would do just as well.
This approach works regardless of where the .jar files are located, in particular it also works for extensions (which are hard to locate because they don't appear on the classpath). It also works when the classes haven't been packed into a jar file at all (useful during development).

Anonymous

> Add a properties file to each plugin (.jar) all with
> the same name such as pluginInfo.properties
> Then use ClassLoader.getResources to obtain a URL for
> each such file. Load each properties file in turn to
> obtain the details for that plugin. It needn't be a
> properties file --- an xml file would do just as
> well.

Yes and exactly this is my problem:

To each plugin JAR I added an INI file. But I don't know (from the main application) which JAR files I will receive, so I need something like a list of available JAR files from WebStart or from the jnlp file.

Sorry if that was not clear, still trying to improve my English ;)

> This approach works regardless of where the .jar
> files are located, in particular it also works for
> extensions (which are hard to locate because they
> don't appear on the classpath). It also works when
> the classes haven't been packed into a jar file at
> all (useful during development).

But how to locate the JAR file. If I got getResources() right it works if I [b]know[/b] the JAR file name, but in my case I don't know the file name and where to scan for the files. And I couldn't scan a HTTP location, because it has to work when I am not connected to the net (or does WebStart manage this??)

mthornton
Offline
Joined: 2003-06-10

First each jar file should contain the 'content' file whether .ini, .properties or .xml with exactly the same name and path (within the jar). Suppose we call them all myPlugin.properties and locate them in the root directory of each jar.

for (Enumeration e=getClassLoader().getResources("/myPlugin.properties");
e.hasMoreElements(); ) {
URL url = (URL) e.nextElement();
InputStream in = url.openStream();
Properties p = new Properties();
p.load(in);
in.close();
// details of a plugin are now in 'p'
}

This code will load the details of each plugin in turn. It will work even if the URL is a web url (e.g. http) because it does not ask for a directory. It merely looks for a myPlugin.properties object in each possible location (i.e. each .jar, classpath directory, extention directory).

If you examine the URLs returned you will find the actual location of each jar file concerned, but you don't need to make any use of this.

Anonymous

> First each jar file should contain the 'content' file
> whether .ini, .properties or .xml with exactly the
> same name and path (within the jar). Suppose we call
> them all myPlugin.properties and locate them in the
> root directory of each jar.

OK, I have this.

> for (Enumeration
> e=getClassLoader().getResources("/myPlugin.properties"

Ah ok, the getResources() would load all myPlugins.properties in the enumeration.

Does that mean if I have a jnlp file like here

[code]






[/code]

I would get an enumeration with 3 elements ([i]Main.jar[/i] does not have a myPlugin.properties) regardless where these files are?

If yes I am fine with webstart, but what do I do when I run the appication from console? The JARs are not in the classpath and they are not loaded automatically :(

Thanks,

Patrick

mthornton
Offline
Joined: 2003-06-10

> I would get an enumeration with 3 elements
> ([i]Main.jar[/i] does not have a myPlugin.properties)
> regardless where these files are?

Correct.

> If yes I am fine with webstart, but what do I do when
> I run the appication from console? The JARs are not
> in the classpath and they are not loaded
> automatically :(
You can add a CLASS-PATH entry to the manifest of the main jar file which references the other jars (and start the application using -jar), or add the jars to the extension directory, or just include them in the classpath.

Mark

Anonymous

> You can add a CLASS-PATH entry to the manifest of the
> main jar file which references the other jars (and
> start the application using -jar), or add the jars to
> the extension directory, or just include them in the
> classpath.

Extension directory is a nice idea, I think I can go with that. Thank you Mark, you helped me a lot :)