views:

258

answers:

2

I have a simple class that imports another class from another jar. Everything compiles great, but trying to run it...

$ jar tvf ../../pig-2.1.jar  | grep TupleFact
1641 Mon Feb 02 17:56:32 UTC 2009 org/apache/pig/data/DefaultTupleFactory.class
2289 Mon Feb 02 17:56:30 UTC 2009 org/apache/pig/data/TupleFactory.class
$ javac ../src/Convert.java -classpath `echo ../lib/* ../../lib/* | sed 's/ /:/g'`
$ java Convert -classpath `echo ../lib/* ../../lib/* | sed 's/ /:/g'`
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pig/data/TupleFactory
        at Convert.<clinit>(Convert.java:31)
Caused by: java.lang.ClassNotFoundException: org.apache.pig.data.TupleFactory
        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)
        ... 1 more

Any ideas? How do you start debugging this?

+2  A: 

You have to put class name after the options, like this:

$ java -classpath <...> Convert
bryantsai
+7  A: 

I think that the problem is in the way you are running the command:

java Convert -classpath `echo ../lib/* ../../lib/* | sed 's/ /:/g'`

should be

java  -classpath `echo ../lib/* ../../lib/* | sed 's/ /:/g'` Convert

The command line syntax for the "java" command is:

javac [ <options for the JVM> ... ] <classname> [ <application args> ... ]

If you put the "-classpath" option after the classname, it will be treated as application arguments and you'll execute your application using the default classpath.

Stephen C