Jython 2.7.0 UnsupportedClassVersionError during installation

1.3k Views Asked by At

After successfully installing jython 2.7.0 on my own computer and writing some code that uses it, I attempted to install it on a server running Ubuntu 14.04.2 LTS. My java version is:

java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

My error during installation is:

Generating start scripts ...
Installing pip and setuptools
 90 %
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/python/util/jython : Unsupported major.minor version 51.0

Interestingly, if I run the installation as super user, and then also run the jython executable in the bin directory as super user, it works:

jython-2.7.0/bin$ sudo ./jython 
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_51
Type "help", "copyright", "credits" or "license" for more information.

But if I try to run the jython executable as a normal user (after installing as super user or normal user), then I get the same UnsupportedClassVersionError:

jython-2.7.0/bin$ ./jython 
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/python/util/jython : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.python.util.jython.  Program will exit.

I checked the java version for both super user and my normal user, and it's exactly the same. Any ideas on what the problem is here?

1

There are 1 best solutions below

0
On

Jython has a package cache that scans jars at startup and saves some information to python.cachedir. The user that first runs jython with a default install causes the cachedir to be created and initially populated -- with that user's permissions. In your case, the umask of root probably set the permissions to be unreadable by any other user -- making the jython classloader think that it's having problems reading default jars. If you had used a regular user the first time, you would have seen the permissions errors trying to create the cachedir.

If you don't want to set a cachedir for each user using a registry file, java properties, or modifying the jython startup script, then it should be sufficient to give everyone default rw permissions to the cachedir. If that's the case something like this should fix your issue (you might have to +x the cachedir/packages directory too):

JYTHON_HOME=$(sudo jython -c 'import java;print java.lang.System.getProperty("python.home")')
sudo chmod a+rwx ${JYTHON_HOME}/cachedir ${JYTHON_HOME}/cachedir/packages
sudo chmod -R a+rw ${JYTHON_HOME}/cachedir