简体   繁体   中英

Use existing Java classes from Jython REPL?

I have a massive, unfamiliar Java codebase that I need to use in one of my projects, and unfortunately it's one of those situations where almost nothing is documented, and the very few things that are documented are of the " setFoo(Foo foo) - sets the foo. " variety. So the documentation generated with javadoc is not as helpful as it could be.

I'm more of a Lisp and Python guy myself, so my first thought was that I could learn a lot by interactively playing with some of the relevant classes. Enter the Jython REPL. The problem is that I can't figure out how to set the...the whatever (classpath?) to use them. Assume that I have two directories containing the subdirectories containing the .java files: ~/project/foo/src/ and ~/project/bar/src/ .

Thanks in advance.

It sounds like you first need to compile those Java classes (you've referenced src directories in your question).

Once you have classes compiled, you can reference them via the classpath.

eg

>>> import sys
>>> sys.path.append(r'C:\temp\sample.jar') 
>>> from org.my.package import MyClass

More info in this document

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM