question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pyjnius custom classpath exception

See original GitHub issue

I am using the latest pyjnius from pip: 1.0.2 I have set up my CLASSPATH in .bash_profile (Ubuntu 12.04 LTS 64 bit). Then, did source ~/.bash_profile. echo $CLASSPATH /home/2010/giasu/dev/opinion/opinion/java/stanfordCorenlp/bin:/home/2010/giasu/dev/opinion/opinion/java/opinion/bin:/home/2010/giasu/dev/opinion/external/java/libs/*

Then I opened an IPython session:

IPython 2.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import os

In [2]: print os.environ['CLASSPATH']
/home/2010/giasu/dev/opinion/opinion/java/stanfordCorenlp/bin:/home/2010/giasu/dev/opinion/opinion/java/opinion/bin:/home/2010/giasu/dev/opinion/external/java/libs/*
Now, I tried to access one class from from the package: opinion.nlp
In [3]: from jnius import autoclass

In [4]: autoClass = autoclass('opinion.nlp.SentenceDetector')
---------------------------------------------------------------------------
JavaException                             Traceback (most recent call last)
<ipython-input-4-1c9e6bf51096> in <module>()
----> 1 autoClass = autoclass('opinion.nlp.SentenceDetector')

/diskless/aspect-5/giasu/virtualenvs/opinion/lib/python2.7/site-packages/jnius/reflect.pyc in autoclass(clsname)
    104 
    105     #c = Class.forName(clsname)
--> 106     c = find_javaclass(clsname)
    107     if c is None:
    108         raise Exception('Java class {0} not found'.format(c))

/diskless/aspect-5/giasu/virtualenvs/opinion/lib/python2.7/site-packages/jnius/jnius.so in jnius.find_javaclass (jnius/jnius.c:7192)()

JavaException: Class not found 'opinion/nlp/SentenceDetector'

There is SentenceDetector class in: /home/2010/giasu/dev/opinion/opinion/java/opinion/bin:

[giasu][aspect-5][~] ls /home/2010/giasu/dev/opinion/opinion/java/opinion/bin/opinion/nlp/
SentenceDetector.class

I can access the jdk libraries:

In [5]: from jnius import autoclass

In [6]: autoClass = autoclass('java.util.ArrayList')
No exception.

This is my JDK:

[giasu][aspect-5][~] java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1~0.12.04.2)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

This is how I installed pyjnius:

pip install jnius
Downloading/unpacking jnius
  Downloading jnius-1.0.2.tar.gz
  Running setup.py (path:/diskless/aspect-5/giasu/virtualenvs/opinion/build/jnius/setup.py) egg_info for package jnius

Requirement already satisfied (use --upgrade to upgrade): cython in /diskless/aspect-5/giasu/virtualenvs/opinion/lib/python2.7/site-packages (from jnius)
Installing collected packages: jnius
  Running setup.py install for jnius
    cythoning jnius/jnius.pyx to jnius/jnius.c
    building 'jnius' extension
    gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/jvm/java-7-openjdk-amd64/include -I/usr/lib/jvm/java-7-openjdk-amd64/include/linux -I/diskless/aspect-5/giasu/packages/python-as-2.7.6/include/python2.7 -c jnius/jnius.c -o build/temp.linux-x86_64-2.7/jnius/jnius.o
    gcc -pthread -shared build/temp.linux-x86_64-2.7/jnius/jnius.o -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm -o build/lib.linux-x86_64-2.7/jnius/jnius.so -Wl,-rpath /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server

Successfully installed jnius
Cleaning up...

This is my OS:

[giasu][aspect-5][~] uname -a 
Linux aspect-5 3.8.0-35-generic #52~precise1-Ubuntu SMP Thu Jan 30 17:24:40 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

This is my Python installation:

[giasu][aspect-5][~] python
ActivePython 2.7.6.9 (ActiveState Software Inc.) based on
Python 2.7.6 (default, Feb 27 2014, 14:04:52) 
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Note that the Python distribution is from ActivePython. I installed Python 2.7.6.9 64 bit as non-root from here: http://downloads.activestate.com/ActivePython/releases/2.7.6.9/ActivePython-2.7.6.9-linux-x86_64.tar.gz

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
abrasivecommented, May 10, 2014

Version 1.0.2 doesn’t support setting the classpath. You need to use 1.0.3 or a version from git.

0reactions
giasuddincommented, May 10, 2014

That worked. Thanks for your help, James.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pyjnius "Class not found" when importing jar file - Stack Overflow
It's strange that it throws a 'Class not found' exception, instead of something more descriptive. Changing the target output to 1.7 fixed my...
Read more >
API — Pyjnius 1.0a1 documentation - Read the Docs
If no classpath is provided and CLASSPATH is not set, the path defaults to '.' . This functionality is not available on Android....
Read more >
Is there any way to access custom java class by using pyjnius ...
Let's say I have a custom java file 'myjavaclass.java' located in an arbitrary directory '/path/to/myfile/src/org/myjavapackage'.
Read more >
Pyjnius Documentation - Read the Docs
Pyjnius is a Python library for accessing Java classes. It either starts a new JVM inside ... javap -s -classpath android.jar android.app.
Read more >
[x3d-public] I played a little. Re: Scene Access Interface ...
__call__ (jnius\jnius.c:29079) jnius.JavaException: No methods matching your arguments Don, can you provide a matching method in X3DJSAIL?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found