Why IKVM doesn't support Jython library? - java

We have a huge Java project and decided to port a part of it to .NET (GUI, etc.). To speed up process we're using IKVM (JVM for .NET). In most cases it works fine but when I reach to Jython code then it got stuck and then throws the exception java.lang.NoSuchMethodException and after PyException. It occures within method PythonInterpreter.interpreter.exec.
Even for simple example:
Java:
class Main {
public static String printIt() {
PythonInterpreter pi = new PythonInterpreter();;
pi.set("integer", new PyInteger(122));
pi.exec("result = integer * integer");
pi.exec("print('hello!')");
return "hello";
}
}
C#:
var code = Main.printIt();
What restriction or limitation causes the exceptions? In general where to find all limitation of IKVM (already searched a lot, nothing relating to this case found). Thanks.
UPDATE:
Using IKVM 8.1 and jython-standalone-2.5.3, JDK 1.8, .NET 4.5
Here is a stacktrace:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "src_python\Util.py", line 2, in <module>
from com.trueship.jyinterface import PyUtil
File "src_python\Util.py", line 2, in <module>
from com.trueship.jyinterface import PyUtil
java.lang.NoClassDefFoundError: junit.framework.TestCase
at Java_java_lang_ClassLoader.defineClass1(Unknown Source)
at IKVM.Internal.AssemblyClassLoader.DefineDynamic(Unknown Source)
at IKVM.Internal.AssemblyClassLoader.LoadDynamic(Unknown Source)
at IKVM.Internal.AssemblyClassLoader.LoadClassImpl(Unknown Source)
...
at org.python.core.Py.runCode(Py.java:1275)
at org.python.core.Py.exec(Py.java:1319)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:207)
at com.trueship.jyinterface.Jyb.findClass(Jyb.java:113)
at com.trueship.jyinterface.Jyb.initUtil(Jyb.java:90)
at com.trueship.jyinterface.Jyb.<init>(Jyb.java:77)
at com.trueship.jyinterface.Jyb.getInstance(Jyb.java:102)
at com.trueship.cordage.orders.JSONOrderParser.parseOrder(JSONOrderParser.java:41)
at com.trueship.cordage.readycloud.ReadyCloudApiClient.getOrders(ReadyCloudApiClient.java:302)
at com.trueship.cordage.readycloud.ReadyCloudApiClient.downloadOrders(ReadyCloudApiClient.java:264)
at cli.ReadyShipper.Windows.MainWindow.DownloadOrders(MainWindow.xaml.cs:75)
at cli.ReadyShipper.Windows.MainWindow.<.ctor>b__1(MainWindow.xaml.cs:49)
at cli.System.Windows.RoutedEventHandlerInfo.InvokeHandler(Unknown Source)
at cli.System.Windows.EventRoute.InvokeHandlersImpl(Unknown Source)

Related

How to export Java JOGL GlueGen project in BlueJ?

I want to export my Java project to a standalone Jar or exe file. I use blueJ as an IDE and I use following libraries: GLOOP, JOGL and GlueGen (aswell as pi4j). Running the program in the IDE itself works flawlessly, however when I export the program as a .jar file and wrap it into an exe with Launch4j I get following error:
Catched IllegalArgumentException: No Jar name in <jar:file:/C:/Users/neche/Desktop/UfoSpiel.exe!/com/jogamp/common/os/Platform.class>, got <UfoSpiel.exe>, while TempJarCache.bootstrapNativeLib() of null (null + null)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:454)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$2.run(Platform.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
at GLOOP.GLRenderer.<init>(GLRenderer.java:90)
at GLOOP.GLKamera.<init>(GLKamera.java:49)
at UfoSzene.main(UfoSzene.java:14)
I use the Operating system Windows 64bit and BLuej version 414
I have googled a lot but never found someone who had the same problem or used the same OS or IDE.
It would be amazing if anyone of you could help.
Here is the main thread code:
import GLOOP.*;
public class UfoSzene
{
public static void main(String[] args)
{
GLKamera kamera;
GLLicht licht;
GLBoden weltall;
UfoSpiel ufoSpiel = new UfoSpiel();
Punkte punkteStand = new Punkte();
weltall = new GLBoden("Weltall.jpg");
kamera = new GLKamera(800,800);
kamera.setzePosition(2000,3001,20);
kamera.setzeBlickpunkt(2000,0,0);
licht = new GLLicht();
ufoSpiel.start();
punkteStand.start();
}
}
Thanks in advance!

Unable to load library 'libtesseract302':Module cannot be found (Windows10)

We are trying to make software for a car parking system using image processing. We used OCR. We intend to use a webcam to obtain images of the license plate when the vehicle leaves and enters. We will then use the number to calculate the time spent inside the park and price tickets based on that.
This is my code:
import java.io.File;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract1;
import net.sourceforge.tess4j.TesseractException;
public class TestOCR {
public static void main(String[] args) {
File imageFile = new File("C:"+File.separator+"projects"+File.separator+"plate.tif");
//ITesseract instance = new Tesseract(); // JNA Interface Mapping
ITesseract instance = new Tesseract1(); // JNA Direct Mapping
try {
//String result = instance.doOCR(imageFile);
//stem.out.println(result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
When I run this, I get this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188)
at com.sun.jna.Library$Handler.<init>(Library.java:123)
at com.sun.jna.Native.loadLibrary(Native.java:255)
at com.sun.jna.Native.loadLibrary(Native.java:241)
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at com.nadeem.app.ocr.TesseractExample.main(TesseractExample.java:16)
Initially we had a NoSuchFieldError and after using Maven to fix that we encountered this problem.
Basically this error would come either of below reasons
dll path are not specified properly. You can add in vm argument as below. -Djna.library.path=<folder_contains_dll>, This folder should have three dll files gsdll64.dll,liblept168.dll and libtesseract302.dll
You should have Visual C++ Redistributable for VS2012 installed. Windows 10 doesn't have this installed by default.
You may do below steps to start with
Install Visual C++ Redistributable for VS2012 if its not installed
Clone the project from https://github.com/mnadeem/ocr-tess4j-example
Import the maven project in eclipse
Run the Java class TesseractExample.java

Error in reading Ubuntu 14.04 mouse event file (/dev/input/event3) with java programmig

I want to handle mouse event in Linux terminal via java programming. I wrote two program via c++ and java that they do same process.
when i use c++ programming to open and read file ("/dev/input/event3"-mouse event file), there is no problem while running executable file.
(Ubuntu 14.04 terminal and Ubuntu server 14.04 ---> no problem).
But when i used java programming to open and read the same file ,there is a problem while running executable result file "java -jar program.jar" in Ubuntu 14.04 "terminal". No error for opening file , but reading file make an error like this:
java.io.IOException: Invalid argument
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(Unknown Source)
at eventfileopen.m.main(m.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
But when i run the same jar file on Ubuntu server 14.04, there is no error and the program work perfectly.
How can I resolve the problem?(Problem = run the java program on Ubuntu 14.04 with no error.) I guess the problem is related to Ubuntu GUI and JDK,but no idea for resolving that.
My java program code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
public class m {
public static void main(String[] args) {
File f = new File("/dev/input/event3");
FileInputStream is = null;
try {
is = new FileInputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] bytes = new byte[16];
while(true){
try
{
is.read(bytes);
} catch (IOException e)
{
e.printStackTrace(); //-------> error while run on Ubuntu 14.04 and no error on Ubuntu server
}
System.out.println(Arrays.toString(bytes));
}
}
}
Check that your buffer size is correct.
In recent Linux kernels size of input_event structure is dependent on many things, but mainly on cpu architecture. Here's its declaration:
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
On 32-bit systems it's very likely that your buffer size is accepted(16 bytes).
On 64-bit systems it's very likely that the buffer should be no less than 24 bytes. The reason is that timeval struct takes twice as much space(8 bytes more) than on 32-bit systems.
I haven't found a reliable way to get input_event struct size from Java and personally I use JNI for that.

java using jython has wrong python version

Im trying to use java to run a python function through jython.jar. I'm using a python module that is downloaded from web which needs python 2.6 or higher. I'm pretty sure that my python is version 2.7.2. However, when I try to run the java program, it continues to report python 2.5 detected. How can I resolve this?
My code is:
public class Main {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
...
//cmd
String command = "\"xml\\" + name2 + "\"";
PythonInterpreter python = new PythonInterpreter(null, new PySystemState());
PySystemState sys = Py.getSystemState();
sys.path.append(new PyString("C:\\Python27\\Lib\\site-packages"));
python.execfile("work1.py");
}
}
}
}
And the error is:
Exception in thread "main" Traceback (most recent call last): File "work1.py", line 8, in <module>
import networkx as nx File "C:\Python27\Lib\site-packages\networkx\__init__.py", line 39, in <module>
raise ImportError(m % sys.version_info[:2]) ImportError: Python version 2.6 or later is required for NetworkX (2.5 detected). Java Result: 1
You need to use Jython 2.7b3, 2.7 beta adds language compatibility with CPython 2.7...
http://comments.gmane.org/gmane.comp.lang.jython.devel/6145
2.7 beta 4 will come in July and after that a feature freeze. I suggest you join the python-dev mailing list to stay aware of new releases. Hope this helps

how to install .jar file onto zend server CE and call it from a php script

I have the zend javabridge working. Now I want to call a .jar file myWebTest.jar with an class of the same name. Then i want to call a function testWeb which returns a hello world string.
This in on 32bit Win 7 professional system
I added myWebTest.jar to the classpath located in /zend/zendserver/etc/java_bridge_server.ini:
[JAVA_BRIDGE_SERVER]
CLASSPATH="C:\Program Files\Zend\ZendServer\bin\javamw.jar;C:\Program Files\Zend\ZendServer\bin\myWebTest.jar;."
This path is correct.
I have restarted zend server and the code I am trying is:
$jObj = new Java("myWebTest");
// Print date through the object
print $jObj->testWeb("jim");
The log:
1 {main}
thrown in C:\Program Files\Zend\Apache2\htdocs\javaObject.php on line 4
[08-Dec-2011 11:44:48] PHP Fatal error: Call to a member function testWeb() on a non-object in C:\Program Files\Zend\Apache2\htdocs\javaObject.php on line 6
[08-Dec-2011 11:45:51] PHP Fatal error: Uncaught exception 'JavaException' with message 'Java Exception java.lang.ClassNotFoundException: myWebTest
java.lang.ClassNotFoundException: myWebTest
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
in C:\Program Files\Zend\Apache2\htdocs\javaObject.php:4
Stack trace:
#0 C:\Program Files\Zend\Apache2\htdocs\javaObject.php(4): *No Class!*->jbridge('myWebTest')
#1 {main}
thrown in C:\Program Files\Zend\Apache2\htdocs\javaObject.php on line 4
I can't find a how to on this anywhere. TIA Jim
From the documentation of Java
object java(string $class_name [ , ... ])
Parameters
class_name: Class name to create
...: Additional arguments are treated as constructor parameters
Return Value: The Java object that was created, NULL otherwise
Not to be confused, actually class name needs to be the full qualified Name of the class. As an example, if you have a class as below:
package experiment;
public class Test {
....
}
Here class name is: Test
Fully qualified name: experiment.Test
So to instantiate this class in PHP, you need to write:
$test = new Java("experiment.Test");
Additionally according to your exception log
Java Exception java.lang.ClassNotFoundException: myWebTest
It shows that, it can not find any class named as myWebTest in your class path. Which means either there is no class named myWebTest in the jar file, or jar is not properly loaded.
The argument to Java() is the fully qualified class name of the class you want to access, not the name of the jar file. For example the php java bridge docs say,
java("java.lang.Long")->MAX_VALUE
This access the class Long, in the package java.lang
There is some info on java packages and class names here.

Categories