Setting up the JavaSci in CMD - java

Peace be upon you,
Based on this link, I followed the required steps for setting up the JavaSci in Windows; but I encounter this problem
c:\Backups>javac -cp "C:\Program Files\scilab-5.5.0\modules\javasci\jar\org.scilab.modules.javasci.jar;C:\Program Files\scilab-5.5.0\modules\types\jar\org.scilab.modules.types.jar";. TestSciLab.java
c:\Backups>set PATH=%PATH%;"C:\Program Files\scilab-5.5.0\bin"
c:\Backups>java -cp "C:\Program Files\scilab-5.5.0\modules\javasci\jar\org.scilab.modules.javasci.jar;C:\Program Files\scilab-5.5.0\modules\types\jar\org.scilab.modules.types.jar";. TestSciLab
The native library javasci does not exist or cannot be found.
java.lang.UnsatisfiedLinkError: no javasci in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at org.scilab.modules.javasci.Call_ScilabJNI.<clinit>(Unknown Source)
at org.scilab.modules.javasci.Call_Scilab.SetFromJavaToON(Unknown Source)
at org.scilab.modules.javasci.Scilab.initScilab(Unknown Source)
at org.scilab.modules.javasci.Scilab.<init>(Unknown Source)
at org.scilab.modules.javasci.Scilab.<init>(Unknown Source)
at TestSciLab.main(TestSciLab.java:7)
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.scilab.modules.javasci.Call_ScilabJNI.SetFromJavaToON()V
at org.scilab.modules.javasci.Call_ScilabJNI.SetFromJavaToON(Native Method)
at org.scilab.modules.javasci.Call_Scilab.SetFromJavaToON(Unknown Source)
at org.scilab.modules.javasci.Scilab.initScilab(Unknown Source)
at org.scilab.modules.javasci.Scilab.<init>(Unknown Source)
at org.scilab.modules.javasci.Scilab.<init>(Unknown Source)
at TestSciLab.main(TestSciLab.java:7)
c:\Backups>
The only difference that you see in the above screen and the guides in the link is the place of %path% that I moved it to the beginning. But do not doubt! even I checked it with the reverse order and I got the error.
My code is as simple as
import org.scilab.modules.javasci.JavasciException.InitializationException;
import org.scilab.modules.javasci.Scilab;
public class TestSciLab {
public static void main(String[] args) throws InitializationException {
Scilab sci = new Scilab();
}
}
Any lighting up points?

On Windows, you just need to add Scilab's bin folder to %PATH%.

Related

java.lang.ClassNotFoundException Error when trying to inject into running VM

I am trying to inject a .jar file in a running VM.
I've added tools.jar in the build path in eclipse, but when I try to run the injector, this error pops up. How should I add tools.jar to the project?
Full error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
at src.testinjector.MainClass.main(MainClass.java:13)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
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)
... 1 more
you may try:
Give the path to tools.jar instead of being dependent on JAVA_HOME.
Note: JAVA_HOME/path to jdk/bin/ should not have any space.
By default, the "tools.jar" classes are not loaded, your options are to either use a jdk that does load it, include tools.jar in your jar, or forcefully load it with the method below, (note: this might not work on certain jdk/jvm's)
private static void prepareAttach() throws NoSuchMethodException, MalformedURLException, InvocationTargetException, IllegalAccessException {
String binPath = System.getProperty("sun.boot.library.path");
// remove jre/bin, replace with lib
String libPath = binPath.substring(0, binPath.length() - 7) + "lib";
URLClassLoader loader = (URLClassLoader) [This Class].class.getClassLoader();
Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURLMethod.setAccessible(true);
File toolsJar = new File(libPath + "/tools.jar");
if (!toolsJar.exists()) throw new RuntimeException(toolsJar.getAbsolutePath() + " does not exist");
addURLMethod.invoke(loader, new File(libPath + "/tools.jar").toURI().toURL());
}

java.lang.NoClassDefFoundError: javax/json/Json no maven or IDE

I am trying a simple json java program (no maven or IDE).
This is my java file:
import javax.json.*;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonWriter;
class JsonTest {
public static void main(String[] args){
JsonObject obj = Json.createObjectBuilder()
.add("name", "foo")
.add("num", new Integer(100))
.add("balance", new Double(1000.21))
.add("is_vip", new Boolean(true)).build();
System.out.print(obj);
}
}
In the same directory of this file, I have the jar file:
javax.json-1.0.jar
I don't get any error in compiling:
javac -classpath ./javax.json-1.0.jar JsonTest.java
But when I run the program I get the error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/json/Json
at JsonTest.main(JsonTest.java:10)
Caused by: java.lang.ClassNotFoundException: javax.json.Json
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)
... 1 more
Why am I getting this error when there was no error in compilation. I already searched other questions with this error but unlike them I am not using any IDE or maven. Any help will be appreciated.
You are not running it with the JSON JAR file on the classpath.
Try this:
java -classpath .:./javax.json-1.0.jar JsonTest
Change : to ; on Windows ....

java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder

Summary:
When I try loading a DLL and the language in my computer is set to a non-latin based language (such as Korean), I get the error java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder
If you can help me figure out how to avoid this error, I'd appreciate any help.
I am trying to load a Native DLL Library using:
Native.loadLibrary
But I keep getting these errors:
java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder
at java.nio.file.FileSystems.<unknown>(Unknown Source)
at java.io.File.toPath(Unknown Source)
at sun.security.provider.SeedGenerator$1.run(Unknown Source)
at sun.security.provider.SeedGenerator$1.<unknown>(Unknown Source)
at java.security.AccessController.<unknown>(Unknown Source)
at sun.security.provider.SeedGenerator.getSystemEntropy(Unknown Source)
at sun.security.provider.SecureRandom$SeederHolder.<clinit>(Unknown Source)
at sun.security.provider.SecureRandom$SeederHolder.access$100(Unknown Source)
at sun.security.provider.SecureRandom.engineNextBytes(Unknown Source)
at java.security.SecureRandom.nextBytes(Unknown Source)
at java.security.SecureRandom.next(Unknown Source)
at java.util.Random.nextLong(Unknown Source)
at java.io.File$TempDirectory.generateFile(Unknown Source)
at java.io.File.createTempFile(Unknown Source)
at com.sun.jna.Native.extractFromResourcePath(Native.java:839)
at com.sun.jna.Native.loadNativeLibraryFromJar(Native.java:751)
at com.sun.jna.Native.loadNativeLibrary(Native.java:737)
at com.sun.jna.Native.<clinit>(Native.java:129)
at com.sun.jna.Native.loadLibrary(RefProp.java:246)
I only get this error when I set my language in my computer to Korean (or any other non-Latin language). When I have it as English, I don't have the error.
By the way, I have set the character encoding as UTF-8:
This code:
Charset charset = Charset.defaultCharset();
System.out.println("Character Set: " + charset.displayName());
Gives this result:
Character Set: UTF-8
So I know the encoding is not the problem.
I've read through:
http://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html
OSGi noClassDefFound for java.nio.files.FileSystems$DefaultFileSystemHolder
- Doesn't seem to apply because the error is slightly different.

NoClassDefFoundError eventhough class in in same folder

I executed a main class and got the following error and trace.
This is the console command:
java -cp . net.sf.tinyPayroll.Main
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.hsqldb.Trace
at org.hsqldb.Database.reopen(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
at org.hsqldb.jdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at net.sf.tinyPayroll.dao.DBConnector.connectDataFile(DBConnector.java:88)
at net.sf.tinyPayroll.dao.DBConnector.<init>(DBConnector.java:72)
at net.sf.tinyPayroll.dao.DBConnector.getInstance(DBConnector.java:106)
at net.sf.tinyPayroll.model.DataFile.<init>(DataFile.java:53)
at net.sf.tinyPayroll.Main.main(Main.java:42)
However, all the necessary classes are in the same folder.
Here is the file which is extracted and available in the same folder (the entire library is available in extracted form).
find . -name Trace*
./org/hsqldb/Trace.class
./org/hsqldb/util/Traceable.class
Your exception is:
NoClassDefFoundError: Could not initialize class org.hsqldb.Trace
Which doesn't mean that it cannot find the class org.hsqldb.Trace in your classpath, it means that the class could not be initialized for some reason.
It generally means that a RuntimeException was thrown while either trying to assign a value to a static field or while trying to execute some code in a static block.
For example we will get such issue in the next cases:
class Trace {
static MyClass foo = MyClass.newInstance(); // If it fails while calling newInstance
static {
SomeClass.init(); // If it fails while calling SomeClass.init()
}
...
}
As Nicolas has mentioned this doesn't mean that it cannot find the class org.hsqldb.Trace in your classpath, it means that the class could not be initialized for some reason.
I've checked the code (This might change based on version) http://grepcode.com/file/repo1.maven.org/maven2/hsqldb/hsqldb/1.8.0.1/org/hsqldb/Trace.java
In the class it has some static block which do some processing. Most probably some of the resources are missing in your class path

Unable to run java program from CLI while Netbeans runs same program correclty

Following program runs fine with Netbeans IDE but when i try to run from command prompt i get
Exception in thread "main" java.lang.NoClassDefFoundError: Gcd (wrong name: algo
rithms/Gcd)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
package algorithms;
public class Gcd {
public static int ComputeGcd(int number1, int number2){
if(number2 == 0){ return number1;}
else{
int remainder = number1 % number2;
return ComputeGcd(number2,remainder);
}
}
public static void main(String[] args) {
int a = 32;
int b = 12;
System.out.println(ComputeGcd(a,b));
}
}
You should be in the src directory, running these commands:
...\src> javac algorithms\Gcd.java
...\src> java algorithms.Gcd
(You don't have to compile from that directory, but I would suggest you do so.)
The java command takes the fully-qualified class name, which includes the package name.
move two levels above i.e. src and then do a java algorithms.Gcd
Have you created directory for algorithm, try running the program by commenting package algorithm, it will work...Once assured, you can use
javac algorithms.Gcd.java;
java algorithms.Gcd`
as mentioned by #JonSkeet, you can learn more about the package structures here,
You probably need to see what classpaths Netbeans is providing to Java that your CLI command isn't.
Try removing the package call if you're not using packages, as it can lead to complications.

Categories

Resources