0

I made a Java class using JAI. The class was working fine in Netbeans. Now I have to add cmd.exe and javac.

However, now the class is not working, whatever I've tried from the JAI library. Here is where I use JAI on my class.

import javax.media.jai.JAI;
import javax.media.jai.RenderedImageAdapter;
...
RenderedImage rendimg=JAI.create("fileload","/Users/Blob/Desktop/projet_jni/ressources/init.pgm");
BufferedImage init = new RenderedImageAdapter(rendimg).getAsBufferedImage();

I tried to install JAI with the jai-1_1_3-lib-windows-i586-jdk.exe. I tried to use jai-1_1_3-lib-windows-i586.jar like that (in the cmd) :

javac -cp ../ressources/ressources.jar;../ressources/jai_windows-i586.jar *.java

It compiles normally, but I always get the error :

C:\Users\USER\Desktop\projet_jni\part_java>java Main
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/jai/JAI
    at ImgProcessing.<init>(ImgProcessing.java:46)
    at Fenetre.<init>(Fenetre.java:23)
    at Main.main(Main.java:25)
Caused by: java.lang.ClassNotFoundException: javax.media.jai.JAI
    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)
    ... 3 more

How can I repair this issue?

EDIT :

tried for the same error :

java -classpath "../ressources/ressources.jar;../ressources/jai_windows-i586.jar;." Main

tried :

java -cp ../ressources/ressources.jar;../ressources/jai_windows-i586.jar Main

"Main" can't be found or loaded.

Prune
  • 76,765
  • 14
  • 60
  • 81
Jimolrame
  • 15
  • 5

1 Answers1

0

You need the same class path when running your application, as when you compiled it.

I.e.:

java -cp .;../ressources/ressources.jar;../ressources/jai_windows-i586.jar Main
Harald K
  • 26,314
  • 7
  • 65
  • 111
  • Thank you! I tried that but it says me that the Main class can not be found or loaded. tried to do the other way (see edit) but it don't change anything. – Jimolrame Jan 10 '14 at 21:55
  • @user3178283: I updated the answer, now including current directory in classpath. Without quotes. – Harald K Jan 11 '14 at 10:45
  • There is now the first error again : java.lang.NoClassDefFoundError: javax/media/jai/JAI – Jimolrame Jan 12 '14 at 00:17
  • If on OS X or Linux/Unix, try replacing all ; with : on the command line. I assumed Windows. Different platforms has different separators, has nothing to do with Java. – Harald K Jan 12 '14 at 05:41
  • Hi sorry for the delay, but i'm working with windows. I think maybe I'll try to setup the "Java Advanced Imaging-Image I/O" just in case but I don't think it's from that. – Jimolrame Jan 20 '14 at 09:37