Ticket #12 (closed defect: invalid)

Opened 5 months ago

Last modified 3 months ago

classpath is not settable when running java -jar run.jar

Reported by: marius Assigned to: hannes@helma.at
Priority: normal Milestone: Helma NG 0.3
Component: helma-ng Version: Helma NG 0.2
Keywords: classpath hibernate jar ehcache configuration xml Cc:

Description

When using java -jar parameter setting the classpath via -cp is not supported. Helma property helma.classpath passed via -Dhelma.classpath is not working either. Setting the classpath is essential to provide configuration files for included java archives like hibernate or ehcache. Both applications (hibernate and ehcache) search for their configuration xmls in the java classpath.

Change History

06/12/08 03:15:45 changed by maks

I do not think this is possible. According to the JDK docs for the -jar option:

"...When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored."

But specifically for ehcache (which BTW, looks like a fantastic tool for us to use in helma-ng!) you can specify the config file manually:

CacheManager manager = new CacheManager("src/config/ehcache.xml");

OR completely via code:

CacheManager singletonManager = CacheManager.create();
Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);
manager.addCache(memoryOnlyCache);

(from: http://ehcache.sourceforge.net/samples.html )

I think the second option should be prefered, since then the config could actually come from JSON files via the upcoming App-wide configuration infrastructure, see: ticket:11.

(follow-up: ↓ 3 ) 06/12/08 11:55:09 changed by hannes

Actually, -Dhelma.classpath is working. The trick is just that you need ton include lib/**, which is required for letting java find helma.jar and its dependencies.

So the following should work:

java -Dhelma.classpath=lib/config,lib/** shell.jar

Should we always assume/append lib/** as classpath component, like we do with the module directory and helma.modulepath?

Actually, the global importJar() function should also work to include directories:

importJar('lib/config');

So actually importJar is not a really good name, as importing jar is only one of the things it does. Rename it to importJavaResource()? importClasspath()? Any ideas?

(in reply to: ↑ 2 ; follow-up: ↓ 4 ) 06/14/08 20:17:48 changed by robert.thurnher

Replying to hannes:

Actually, the global importJar() function should also work to include directories: {{{ importJar('lib/config'); }}} So actually importJar is not a really good name, as importing jar is only one of the things it does. Rename it to importJavaResource()? importClasspath()? Any ideas?

I'd be in favour of renaming importJar() to addToClassPath() and enabling it to apart from including single file resources (of e.g. possible file types JAR, XML, Java properties etc.) also whole directories (which can again contain JAR, XML, Java properties etc. files) to the Java class path.

Examples:

 addToClassPath('hibernate/hibernate3.jar');
 addToClassPath('hibernate');
 addToClassPath('ehcache.xml');
 addToClassPath('hibernate.properties');

(in reply to: ↑ 3 ; follow-up: ↓ 5 ) 06/15/08 18:54:21 changed by hannes

Replying to robert.thurnher:

I'd be in favour of renaming importJar() to addToClassPath() and enabling it to apart from including single file resources (of e.g. possible file types JAR, XML, Java properties etc.) also whole directories (which can again contain JAR, XML, Java properties etc. files) to the Java class path.

You can't add individual resources or classes to the classpath, only the directories or jar files that contain them. So functionality-wise, there's nothing missing: Adding a directory to the classpath will make contained configuration files available to java files through the classloader.

But what I'm considering is to make "path/*" and "path/**" behave a little bit like "path/", i.e. either add the directory itself to the classpath, or any subdirectories that do not contain jar files, or don't have one of their containing directories in the classpath yet.

(in reply to: ↑ 4 ) 06/15/08 19:47:38 changed by robert.thurnher

Replying to hannes:

Replying to robert.thurnher:

I'd be in favour of renaming importJar() to addToClassPath() and enabling it to apart from including single file resources (of e.g. possible file types JAR, XML, Java properties etc.) also whole directories (which can again contain JAR, XML, Java properties etc. files) to the Java class path.

You can't add individual resources or classes to the classpath, only the directories or jar files that contain them. So functionality-wise, there's nothing missing: Adding a directory to the classpath will make contained configuration files available to java files through the classloader.

Thanks for the clarification.
Though, I'm wondering why the config files don't seem to be made available in the following line of hibernate.js then?

08/22/08 15:06:32 changed by hannes

  • status changed from new to closed.
  • resolution set to invalid.