Loading resources from a class in Jython using 'classpath:'

I have a relatively large Java application that will benefit from love in Python. To this end, I worked to launch it and run in Jython. My current checkpoint is getting the correct class path.

I applied two approaches to setting the classpath:

  • Using the shell script, I created a jars list and executed java -cp ${CP} -jar jyton.jar , where $ CP is the list of banners needed for my application. This does not seem to work. I can’t import any classes from these jars, instead I get only ImportError: No module named apache .
  • Using the bootstrap python script, I created a list of paths using glob and added them to the current path using [sys.path.append(path) for path in JAR_LIST] . This seems to work correctly; Now I can import any classes I need from the included jars.

The above is a bit confusing, since most of the information I could find is aimed at using $ CLASSPATH and -cp to add your jars, but I can't get this to work. So the question is still: # 2 the correct way to add dependencies to your classpath when using Jython?

The main reason I questioned my methods is that I still have problems making full use of my application. Several places in my application respect resources using relative URLs: classpath:some-critical-file.xml

some-critical-file.xml and several of my classes are in the same jar. I can import classes from this jar, but any attempts to load my xml using classpath:some-critical-file.xml lead to java.io.FileNotFoundException

Any insight into why my classes are available, but relative resource paths using classpath: will not be very valuable. I am now at a loss.

+4
source share
2 answers

Recently, I came across a little weirdness in the classroom. Have you tried using the old school:

CLASSPATH = $ {CLASSPATH}: your.jar

CLASSPATH export

jython your_script.jy

0
source

If you call a separate jar using java -jar, then from the Java Documentation ...

-jar

When you use this parameter, the JAR file is the source of all user classes, and other paths to the user class path are ignored.

Thus, when using -jar it is not possible to add anything to the classpath. See this answer for a solution - basically add jython.jar to the classpath (using -cp or CLASSPATH) and run the org.python.util.jython class directly.

0
source

All Articles