Loading own class fails

102 views
Skip to first unread message

peter.m...@gmail.com

unread,
Sep 25, 2015, 3:07:00 AM9/25/15
to PyJNIus development ML
Hi,


this is what i got on drive:
ls -alh sax/
total
172K
drwxr
-xr-x 5 julius julius 4.0K Sep 24 22:17 .
drwxr
-xr-x 6 julius julius  80K Sep 24 22:18 ..
-rw-r--r-- 1 julius julius  16K Jul 21 13:20 SaxCalculations.java.



from the directory above sax this code is executed:
from jnius import autoclass
tmp
= autoclass('sax.SaxCalculations')
print tmp.countPatterns("abc")

countPatterns is a public method in SaxCalculations
python pyjniustest.py
Traceback (most recent call last):
 
File "pyjniustest.py", line 11, in <module>
    tmp
= autoclass('sax.SaxCalculations')
 
File "/home/julius/.local/lib/python2.7/site-packages/jnius/reflect.py", line 162, in autoclass
    c
= find_javaclass(clsname)
 
File "jnius_export_func.pxi", line 23, in jnius.find_javaclass (jnius/jnius.c:12356)
jnius
.JavaException: Class not found 'sax/SaxCalculations'



why is that?



Message has been deleted
Message has been deleted

peter.m...@gmail.com

unread,
Sep 25, 2015, 3:44:37 AM9/25/15
to PyJNIus development ML
looks like it missed the part where you put your classes into a jar, but still it wont run (same error as before)



this is my .jar file
META-INF/MANIFEST.MForg/
org
/eclipse/
org
/eclipse/jdt/
org
/eclipse/jdt/internal/
org
/eclipse/jdt/internal/jarinjarloader/
org
/eclipse/jdt/internal/jarinjarloader/JIJConstants.class
org
/eclipse/jdt/internal/jarinjarloader/JarRsrcLoader$ManifestInfo.class
org
/eclipse/jdt/internal/jarinjarloader/JarRsrcLoader.class
org
/eclipse/jdt/internal/jarinjarloader/RsrcURLConnection.class
org
/eclipse/jdt/internal/jarinjarloader/RsrcURLStreamHandler.class
org
/eclipse/jdt/internal/jarinjarloader/RsrcURLStreamHandlerFactory.class
sax
/
sax
/SaxCalculations.class
sax
/Data.class
sax
/Pattern.class
sax
/DataFile$LineReader.class
sax
/DataFile.class
sax
/PlotInformation.class
sax
/CompareTimeSeriesVisually.class
sax
/LoadData.class
sax
/series/
sax
/series/ClassifiedTimeSeries.class
sax
/test/
sax
/test/MapUtilTest.class
sax
/test/SaxCalculationsTest.class
sax
/test/UtilityTest.class
sax
/utility/
sax
/utility/CharacterToValue.class
sax
/utility/Utility.class
sax
/utility/MapUtil$1.class
sax
/utility/MapUtil.class
tmp
/
tmp
/Regex.class
tmp
/TestCase.class
tmp
/CoordValue.class
tmp
/IndexedMatrix.class
tmp
/KeyIndex.class
tmp
/Diverses.class
junit
.jarorg.hamcrest.core_1.3.0.v201303031735.jar




contents of the Manifest file


Manifest-Version: 1.0
Rsrc-Class-Path: ./ junit.jar org.hamcrest.core_1.3.0.v201303031735.ja rClass-Path: .
Rsrc-Main-Class: sax.SaxCalculations
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader







and the new python code:
from jnius import autoclass
import osos.environ['CLASSPATH'] = "/home/julius/sax-test.jar"

SaxCalculations = autoclass('sax.SaxCalculations')
mysax
= SaxCalculations()
print mysax.countPatterns("abc")








peter.m...@gmail.com

unread,
Sep 25, 2015, 3:47:17 AM9/25/15
to PyJNIus development ML
running the java code from the commandline works:

java -cp sax-test.jar sax.SaxCalculations
[-0.67, -0.67, -0.67, -0.67, -0.67, -0.335, -0.335, -0.335, -0.335, -0.335, 0.335, 0.335, 0.335, 0.335, 0.335, 0.67, 0.67, 0.67, 0.67, 0.67]
[-1.0675705, -1.0675705, -1.0675705, -1.0675705, -1.0675705, -0.8167596500000001, -0.8167596500000001, -0.8167596500000001, -0.8167596500000001, -0.8167596500000001, -0.3729806, -0.3729806, -0.3729806, -0.3729806, -0.3729806, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3729806, 0.3729806, 0.3729806, 0.3729806, 0.3729806, 0.8167596500000001, 0.8167596500000001, 0.8167596500000001, 0.8167596500000001, 0.8167596500000001, 1.0675705, 1.0675705, 1.0675705, 1.0675705, 1.0675705]


input is a string and the output is a bunch of numbers.

peter.m...@gmail.com

unread,
Sep 25, 2015, 7:35:42 AM9/25/15
to PyJNIus development ML
and the solution is, the last posting was correct. except a little change to the python code:


import os
os
.environ['CLASSPATH'] = "/home/julius/sax-test.jar"

from jnius import autoclass

first set environ, then import autoclass.
Reply all
Reply to author
Forward
0 new messages