No puedo ejecutar un programa usando jxl

Source fie -> location c:/program files/java/jdk1.6.0_07/bin

import java.io.File;
import java.io.IOException;
import jxl.*;
public class Geeta {

 private String inputFile;

 public void setInputFile(String inputFile) {
  this.inputFile = inputFile;
 }

 public void read() throws Exception  {

  File inputWorkbook = new File(inputFile);

   Workbook w;
  w = Workbook.getWorkbook(inputWorkbook);
   // Get the first sheet
   Sheet sheet = w.getSheet(0);
   // Loop over first 10 column and lines
   Cell a1 = sheet.getCell(0,0);


String stringa1 = a1.getContents();
   System.out.println(stringa1);


 }


 public static void main(String[] args) throws Exception {
  Geeta test = new Geeta();

test.setInputFile("c:/Progra~1/Java/jdk1.6.0_07/bin/jxlrwtest.xls");
  test.read();
 }

}

compiled as javac -classpath jxl.jar Geeta.java

When I try to execute it says.. NoClassDefFoundError

java -jar jxl.jar Geeta

C:\Program Files\Java\jdk1.6.0_07\bin>java -jar jxl.jar Geeta Exception in thread "main" java.lang.NoClassDefFoundError: Geeta Caused by: java.lang.ClassNotFoundException: Geeta at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 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)

Plz. advice...

preguntado el 08 de enero de 11 a las 15:01

2 Respuestas

I had an error with jxl execution, it was about the CLASSPATH

This works to me:

  1. Change or set the CLASSPATH in Environment Variables:

    • Open Explorer (Windows-E)
    • Right-click on Computer
    • Seleccionar propiedades
    • On the "Advanced" Tab select "Environment Variables..."
    • On System variables window, Edit or Add a new variable named: CLASSPATH
    • On Variable Value set the place where jxl.jar is, example: .;C:\YourPath\jxl.jar
  2. Open a new CMD window and compile as usual.

contestado el 15 de mayo de 12 a las 12:05

Your run command should look like this:

java -classpath jxl.jar;. Geeta

Respondido el 08 de enero de 11 a las 18:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.