Jython classpath question
Alan Kennedy
alanmk at hotmail.com
Thu Jul 17 06:28:29 EDT 2003
Tennessee James Leeuwenburg wrote:
> Is it
> correct that Jython can only access Java classes which are inside JAR
> archives in the JYTHON_HOME directory?
No.
Here is an example of accessing java classes in a jar that is at some
non-jython location.
#-- Commands should be same for all platforms, 'cept maybe
'copy'->'cp'
C:\>cd temp
C:\temp>mkdir classpathtest
C:\temp>cd classpathtest
C:\temp\classpathtest>copy C:\jars\oro206\oro206.jar .
1 file(s) copied.
C:\temp\classpathtest>set CLASSPATH=./oro206.jar;
C:\temp\classpathtest>jython
*sys-package-mgr*: processing new jar,
'C:\temp\classpathtest\oro206.jar'
Jython 2.1 on java1.4.2 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import org.apache.oro as oro
>>> dir (oro)
['__name__', 'io', 'text', 'util']
>>>
And here is an example of compiling a java class in the local
directory, and using it from within jython.
#--- file SayHi.java starts here
public class SayHi
{
public SayHi()
{
System.out.println("Hello World!");
}
}
#--- file SayHi.java ends here
Save the above into SayHi.java, then compile it
C:\temp\classpathtest>javac SayHi.java
C:\temp\classpathtest>echo %CLASSPATH%
./oro206.jar;
C:\temp\classpathtest>jython
Jython 2.1 on java1.4.2 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import SayHi
>>> newobj = SayHi()
Hello World!
>>>
> I have a working directory where all my code lives, and because my app is
> under rapid development, I would prefer to avoid creating a JAR file
> every time I want to do some Python scripting?
Examples above should show you the way.
HTH,
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
More information about the Python-list
mailing list