From: Daniel L. <da...@br...> - 2001-06-09 21:44:21
|
On Thursday, June 7, 2001, at 12:04 PM, jython-users- re...@li... wrote: > > I'm likely misunderstanding you on this, but to me creating a java > packages consist of: > > - changing my CLASSPATH envvar by adding root directory. > - create a new package dir (let's call it "foo") in the root dir that > was added to CLASSPATH. > - create my java source files inside the foo directory and add a > "package foo;" to the top of all the source files. > > This is all due to the way java is designed. > > regards, > finn I have "." in my class path, but of course that will not load jars by default. To avoid having to set my environment each time I launch Jython and since there is no command line equivalent to "-jar" in Jython, I have been trying to use jreload with litmited success. One thing that I find confusing is that while I can create a java.class (say foo) with no package enveloping it, jar it with a manifest (say in foo.jar), and read it into a Jython program without having to change my shell environment (e.g. setenv CLASSPATH "foo.jar:${CLASSPATH}" before execution with the following code (foo,.java, jartest.py), // foo.java // public class foo { public foo() { System.out.println ("foo::ctor()"); } } //// ## jartest.py ## import sys import os import jreload def xp(name): return os.path.join(sys.prefix,'./'+name) SomeJar = jreload.makeLoadSet('SomeJar',[xp('.'),xp('foo.jar')]) from SomeJar import foo foo() #### I cannot then simply add a package qualifier to foo.java (say package bar;): the following code fails with "ImportError: No module named bar" even though it resembles the standard javax.swing package type calls. What am I doing wrong? How are java packages you build yourself unlike standard packages or does jreload not handle packages at all? The header comment in jreload.py implies only loading inner classes or * imports fails, but doesn't seem to mention all packages failing. According to the comment in the LoadSet class, contained packages should work. Of course Samuele states the module is experimental. Or am I just doing this wrong? // bar/foo.java // package bar; public class foo { public foo() { System.out.println("foobar::ctor()"); } } //// ## jartest-2.py ## import sys import os import jreload def xp(name): return os.path.join(sys.prefix,'./'+name) X = jreload.makeLoadSet('X',[xp('.'),xp('foobar.jar')]) from X.bar import foo X.bar.foo() #### |