running python using jython - java

I want to run a python function using jython..
Taking the example from this site.
http://sundaycomputing.blogspot.com/2011/01/python-udfs-from-pig-scripts.html
Now when i run the script (pig -f myscript.pig
It returns me this error
Pig Stack Trace
---------------
ERROR 2998: Unhandled internal error. org/python/core/PyException
java.lang.NoClassDefFoundError: org/python/core/PyException
at org.apache.pig.scripting.jython.JythonScriptEngine.registerFunctions(JythonScriptEngine.java:127)
at org.apache.pig.PigServer.registerCode(PigServer.java:567)
at org.apache.pig.tools.grunt.GruntParser.processRegister(GruntParser.java:421)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:419)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:188)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:164)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:81)
at org.apache.pig.Main.run(Main.java:427)
at org.apache.pig.Main.main(Main.java:108)
Caused by: java.lang.ClassNotFoundException: org.python.core.PyException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 9 more
================================================================================
I am guessing its because of the first line.. REGISTER udf.py USING jython AS udf;
and that I have to specify jython path? (since i am running this code on cluster.. i dont think i have set this thing up)..
Now... since i dont know much of java.. hence switched on python ... but how do i make this code run??
What sort of setup i have to do on my env... to debug this problem.
Thanks

Add $PIG_HOME/lib/jython.jar to your PIG_CLASSPATH environment variable.

Related

Failing to start java program ClassNotFound exception received

Trying to start java program on linux but it fails to locate JSoup jar file. I have checked other questions and found on how to add libraries while compiling and while trying to run it but I am not sure if I am doing it correctly because it still fails to load the library....
I enter the following commands:
root#vps5441:/var/www/var/www/TimetableLoader# javac -cp /var/www/var/www/TimetableLoader/jsoup-1.8.1.jar:/var/www/var/www/TimetableLoader/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar. TimetableLoader.java
root#vps5441:/var/www/var/www/TimetableLoader# java -cp /var/www/var/www/TimetableLoader/jsoup-1.8.1.jar:/var/www/var/www/TimetableLoader/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar. -classpath /var/www/var/www/TimetableLoader/ TimetableLoader
And I get the following error when the program tries to access the JSoup library.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at TimetableLoader.main(TimetableLoader.java:46)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
I assume jsoup-1.8.1.jar is in the current directory?
You don't generally need both -classpath and -cp. It's probably ignoring the values given by -cp as a result.
Put your own classes ahead of the 3rd-party ones.
You're already in /var/www/var/www/TimetableLoader so keep it simple:-
root#vps5441:/var/www/var/www/TimetableLoader# java -cp .:jsoup-1.8.1.jar:mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar TimetableLoader
(Best to get out of the habit of running things as "root" unless you have a genuine need, just sayin')

Running a java program via nailgun

Can someone please explain how do I start a program called main.java using Nailgun. It's been a complete nightmare for me and I cannot find any sort of tutorial on the web which explains it clearly.
Do I need to include anything extra in my program to run them?
I'm trying to follow the instructions given on the Nailgun website where it says:
Launch the Nailgun server with "java com.martiansoftware.nailgun.NGServer"
But the output I get is:
Error: Could not find or load main class com.martiansoftware.nailgun.NGServer
Also, when I try to run my compiled java program, the output is:
java.lang.ClassNotFoundException: main
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at com.martiansoftware.nailgun.NGSession.run(NGSession.java:261)
I think the idea with nailgun is that you have to include the classpath when you launch the server, like this:
$ java -cp /usr/share/java/nailgun-0.9.0.jar:path/to/myapp.jar -server com.martiansoftware.nailgun.NGServer 127.0.0.1 &
NGServer started on 127.0.0.1, port 2113.
[1] 22443
$ ng-nailgun com.user4215685.main

Java - NoClassDefFoundError on starting up local version of DynamoDB

I'm trying to start local version of DynamoDB on the command line (OSX) using the following command as specified in the documentation:
java –Djava.library.path=. -jar DynamoDBLocal.jar
But getting the following errors:
Exception in thread "main" java.lang.NoClassDefFoundError: �Djava/library/path=/
Caused by: java.lang.ClassNotFoundException: �Djava.library.path=.
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Any ideas on how to resolve this issue?
The � shows that it may be a character, which looks like hyphen '-' . Please inspect this.
Also, whenever you are using -D option, its best practice to use a complete jar name (rather than wild card). This will make sure that you are missing nothing.

Not able to print GC details

I am trying to print the GC details for a test program in eclipse.I want to set it only for my program so I went to Run>Run Configurations and in VM arguments gave this:
-Xms1024M -Xmx1024M –XX:+PrintGCDetails –XX:+PrintGCTimeStamps
However when I do this and run my program I get the following error:
java.lang.NoClassDefFoundError: –XX:+PrintGCDetails
Caused by: java.lang.ClassNotFoundException: –XX:+PrintGCDetails
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
What am I doing wrong in passing the arguments.
What should tip you off is the error message NoClassDefFoundError: –XX:+PrintGCDetails - the JVM isn't trying to parse it as an option but a class...
Then, look at the dashes before -Xms1024M and –XX:+PrintGCDetails / –XX:+PrintGCTimeStamps - they're different!
Replace the latter ones with the former (ie. "real" dashes/minus-sign) and you're good to go.
Cheers,

NoClassDefFoundError from JavaCC generated code

As part of my study, I am using the JavaCC Eclipse plug-in to create a lexical analysis and parser a parser for a programming language.
The parser is generated succesfully and when I run the generated Java code in Eclipse, it is working perfectly.
However, to easily pass a text file to parse, I would like to run the program from command line. When doing so using java Adder with Adder being the name of my main file, I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: Adder
Caused by: java.lang.ClassNotFoundException: Adder
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Can anyone tell me how to fix this error? I have read that I might have to modify my path but I am unsure what to add to the path.
At runtime JVM is not able to find the class in classpath. Please make sure that you include java class in system classpath

Categories

Resources