Tess4J InvocationTargetException - java

I have a problem running the below java code outside of the eclipse compiler. Inside the compiler it works fine, but after exporting as a runnable jar I get an InvocationTargetException. I believe it is relevant to the dll files but after reading other solutions here and tryinging to implement them the problem remained unresolved. So my question is it possible to configure eclipse, through code or settings, to export the program correctly?
Relevant Code
BTW C:\Program Files\Tesseract-OCR contains tessdata, gsdll64.dll, liblept170.dll, libtesseract303.dll
Maven Dependencies are tess4j, junit, ghost4j
public Bot() {
System.setProperty("jna.library.path", "C:/Program Files/Tesseract-OCR");
ocr2 = new Tesseract();
ocr2.setDatapath("C:/Program Files/Tesseract-OCR");
initLists();
System.out.println(scan(0,0,500,500));
}
public String scan(int x, int y, int x2, int y2) {
BufferedImage i = rob.getScreen(x, y, x2, y2);
i = toBufferedImage(i.getScaledInstance(i.getWidth()*2, i.getHeight() *2, Image.SCALE_SMOOTH));
try {
return ocr2.doOCR(i).trim();
} catch (TesseractException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
Error
C:\Users\Blue\Desktop>java -jar bot.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
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)
Caused by: java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:78)
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:40)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:360)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:273)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:256)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:237)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:221)
at debug.Bot.scan(Bot.java:480)
at debug.Bot.<init>(Bot.java:53)
at debug.Bot.main(Bot.java:24)
... 5 more
C:\Users\Blue\Desktop>pause
Press any key to continue . . .

In case anyone has a similar issue what I did was copy the 3 .dll files into my System32 folder. I then got an issue with image.io, which the site had plenty of answers for. My personal solution was exporting the jar as my code and a separate folder for the libraries.

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

LWJGL Controllers in IntelliJ

Every time I try to build a basic example program for using LWJGL controllers, it crashes. Here's the code:
package com.czipperz.blogspot.tests.controllers;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Controllers;
/**
* Created by Chris on 10/23/2014.
*/
public class Main {
//left joystick x and y
private float x, y,
//right joystick x and y. Like the commas?
rx, ry;
//This Controller object MUST BE org.lwjgl.input.Controller NOT net.java.games.input.Controller
private Controller c;
private boolean start;
public static final int BUTTON_A = 1, BUTTON_B = 2, BUTTON_X = 3, BUTTON_Y = 4,
BUTTON_LEFT_BUMPER = 5, BUTTON_RIGHT_BUMPER = 6, BUTTON_SELECT = 7, BUTTON_START = 8,
//When you PRESS the joysticks (click)
BUTTON_LEFT_JOYSTICK = 9, BUTTON_RIGHT_JOYSTICK = 10;
public static void main(String[] args) {
new Main();
}
public Main() {
//Says, find controllers and store them in the Controllers class to JInput. Dont worry bout it.
try {
Controllers.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
// Gets you a shiny "new" controller instance.
// Think of index like you would think of an array.
c = Controllers.getController(0);
//Sets "deadband"
float dead = .06f;
c.setXAxisDeadZone(dead);
c.setYAxisDeadZone(dead);
c.setRXAxisDeadZone(dead);
c.setRYAxisDeadZone(dead);
//Using the controller requires you to call the poll() function to receive new data.
c.poll();
x = c.getXAxisValue();
y = c.getYAxisValue();
rx = c.getRXAxisValue();
ry = c.getRYAxisDeadZone();
//NOTE: getZAxisValue(), getRZAxisValue(), getZAxisDeadZone(), getRZAxisDeadZone() DO NOT WORK
//DPAD = POV
float povx = c.getPovX();
float povy = c.getPovY();
boolean lbumper = c.isButtonPressed(BUTTON_LEFT_BUMPER);
}
}
The problem is that every time I build, this is the log: (Sorry I just can't hit space that many times)
"C:\Program Files\Java\jdk1.8.0_25\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;C:\Users\Chris\workspace\Controllers\out\production\Controllers;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lzma.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\jinput.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_test.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl-debug.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\asm-debug-all.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util_applet.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\AppleJavaExtensions.jar;C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.czipperz.blogspot.tests.controllers.Main
WARNING: Found unknown Windows version: Windows 8.1
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
java.lang.UnsatisfiedLinkError: no jinput-dx8_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.DirectInputEnvironmentPlugin$1.run(DirectInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.DirectInputEnvironmentPlugin.loadLibrary(DirectInputEnvironmentPlugin.java:67)
at net.java.games.input.DirectInputEnvironmentPlugin.<clinit>(DirectInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
java.lang.UnsatisfiedLinkError: no jinput-raw_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.RawInputEnvironmentPlugin$1.run(RawInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.RawInputEnvironmentPlugin.loadLibrary(RawInputEnvironmentPlugin.java:67)
at net.java.games.input.RawInputEnvironmentPlugin.<clinit>(RawInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init> (DirectAndRawInputEnvironmentPlugin.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at org.lwjgl.input.Controllers.getController(Controllers.java:116)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:38)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
net.java.games.input.DirectAndRawInputEnvironmentPlugin is not supported
Process finished with exit code 1
I know this thread is old, but for people who are searching for the solution.
The answer is, you have to include the native libs to your project. For the use of jinput.jar you have to include following libs:
jinput-dx8.dll
jinput-dx8_64.dll
jinput-raw.dll
jinput-raw_64.dll
You can download the natives here DOWNLOAD.
You will get a jar-file. Unzip the file with winrar to get the dll-files.
Now go to project and open the context menu with a click on the right mouse button -> Build Path -> Configure Build Path -> Choose the Libraries tab -> Click on the little arrow next to the jinput.jar to expand the view -> Make a double click with the left mouse button on Native library location -> Choose the directory of the dll-files.
Confirm the dialogs and try to run your program again.
In LWJGL there is a "native/" folder containing the respective native libraries for each platform/OS. Just choose your platform and set java.library.path to that directory.
This is your problem.
First Step:
Create a folder and rename it to LWGJL_New then in that folder create two other folders and rename the first on libs and the second one natives.
Now go to the LWGJL library that you have downloaded. Copy the jar files to LWGJL_New/libs. Then go to the LWGJL library that you have downloaded, in it, there is a folder containing respective native libraries for each platform/OS.
Choose one of them that you need and copy it to LWGJL_New/natives.
Second step:
Go to the module settings of your project(F4) then click library.Click add sign(+).Click on java. Now find the LWGJL_New folder and in it click on the jar folder and click ok. Then Click on Apply and ok.
Third step:
Now if you run your project you will occur that problem, So go to the Edit Configuration part
Then in VM options write this:
-Djava.library.path="***"
Instead of star signs write the address of the native folder that we have just created.
For example ->
D:\LWGJL_New\natives\windwos
D:\LWGJL_New\natives\linux
Then click on OK.
Then run your project.

JAVA - path issue (works in eclipse, not in cmd)

Why the following iniciation works in eclipse:
private static MaxentTagger maxentTagger = new MaxentTagger("c:\\DP\\lemma\\models\\english-left3words-distsim.tagger");
but in command line it throws:
java.lang.reflect.InvocationTargetException
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(JarRsrcLoa
der.java:58)
Caused by: java.lang.ExceptionInInitializerError
at dp.beans.MySearch.<init>(MySearch.java:122)
at dp.runable.Main.main(Main.java:25)
... 5 more
Caused by: java.lang.IllegalArgumentException: name
at sun.misc.URLClassPath$Loader.findResource(Unknown Source)
at sun.misc.URLClassPath.findResource(Unknown Source)
at java.net.URLClassLoader$2.run(Unknown Source)
at java.net.URLClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(Unknown Source)
at java.lang.ClassLoader.getResource(Unknown Source)
at java.net.URLClassLoader.getResourceAsStream(Unknown Source)
at edu.stanford.nlp.io.IOUtils.findStreamInClasspathOrFileSystem(IOUtils.java:370)
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:399)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:646)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:284)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:248)
at dp.data.Settings.<clinit>(Settings.java:80)
... 7 more
Settings.java:80 corresponding with MaxentTagger iniciation..
Is there a different way to declare windows path, which works in both, eclipse and cmd?
update (the findStreamInClasspathOrFileSystem method):
private static InputStream [More ...] findStreamInClasspathOrFileSystem(String name) throws FileNotFoundException
{
String path = null;
if (name.startsWith("/")) {
path = name.substring(1);
}
// - even though this may look like a regular file, it may be a path inside a jar in the CLASSPATH
// - check for this first. This takes precedence over the file system.
InputStream is = null;
if (path != null) {
is = IOUtils.class.getClassLoader().getResourceAsStream(path);
// windows File.separator is \, but getting resources only works with /
if (is == null) {
is = IOUtils.class.getClassLoader().getResourceAsStream(path.replaceAll("\\\\", "/"));
}
}
// if not found in the CLASSPATH, load from the file system
if (is == null) is = new FileInputStream(name);
return is;
}
update: no matter if i change the path to:
"c:/DP/lemma/models/english-left3words-distsim.tagger");
"c:\\\\DP\\\\lemma\\\\models\\\\english-left3words-distsim.tagger");
its behaviour is still the same (works in eclipce, not in cmd)
Your code seems to load a resource from the classath, using the ClassLoader. The path should take the following form:
com/yourcompany/yourapp/english-left3words-distsim.tagger
where com.yourcompany.yourapp is the package where the file resides.
See http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResource%28java.lang.String%29
EDIT:
The code of IOUtils.getInputStreamFromURLOrClasspathOrFileSystem() passes two badly formatted paths (c:\... and c:/...) to ClassLoader.getResourceAsStream(), and expects this method to simply return null instead of throwing an exception, which is wrong. I would simply decide where I want to load the resource rom: either the classpath (and thus use ClassLosader.getResourceAsStream()) or the file system (and thus use new FileInputStream()).

Problems in running a modified Java code

I modified a Java code in Eclipse on my laptop with a Windows O.S. Now I have to run the code on a linux O.S. via SSH. I copied all the files and I tried to compile the code. The compilation went well, so there were no errors in the code. Anyway, when I tried to run it, the following errors appeared on the shell:
[ac6411#epigenetic models]$ java TanaModel
Exception in thread "main" java.lang.NoClassDefFoundError: TanaModel (wrong name: models/TanaModel)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Do you know what kind of the problem is?I'm new in Java coding, so I don't know how to solve it. Thank you.
wrong name: models/TanaModel
This means it expected to find TanaModel.class under the models directory, but found it somewhere else (maybe the current directory?). Put the class file in a the models directory, and run it as
java models.TanaModel
Java expects class files to be organized in directories that mirror the package structure you used in your source code.
java.lang.NoClassDefFoundError: TanaModel (wrong name: models/TanaModel) at
What command did you run, I'm guessing java TanaModel ?
Most likely your TanaModel is declared to be in package models;
Try calling it like this:
java models.TanaModel
If it is a Eclipse security issue, this would help.
//Java Code
try
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
try
{
// Insert code here to do required action (get or open file)
}
catch (Exception e)
{
// Insert code to catch exception from trying to do above action
}
}
}
);
}
catch(Exception e)
{
// Insert code to catch failed doPrivileged()
}
When you try to run your program, try calling it like this:
java models.TanaModel

Categories