Jython :: does the embedded PythonInterpreter handle Python Source Code Encodings? - jython

I am using org.python.util.PythonInterpreter to embed Jython in a Java application. I am using Jython version 2.5.2.
he python script I am interpreting contains UTF-8 literals and so I've added the Python Source Code Encoding at the top of the script as per PEP-0263:
# -*- coding: utf-8 -*-
My script is compiled as follows:
String script = // load from file as a single String ...
PythonInterpreter pi = new PythonInterpreter();
PyCode code = pi.compile(script);
result = pi.eval(code);
However Jython complains with the following trace:
[java] ... : encoding declaration in Unicode string
[java] at org.python.core.ParserFacade.prepBufReader(ParserFacade.java:277)
[java] at org.python.core.ParserFacade.parseExpressionOrModule(ParserFacade.java:119)
[java] at org.python.util.PythonInterpreter.compile(PythonInterpreter.java:259)
[java] at org.python.util.PythonInterpreter.compile(PythonInterpreter.java:256)
[java] at org.python.util.PythonInterpreter.compile(PythonInterpreter.java:250)
Does Jython support UTF-8 in script files?

Here's an anecdotal answer: as installed by Homebrew on macOS, Jython 2.7.1 does support Python Source Code Encoding in the non-embedded command-line interpreter. Hopefully it's also supported beyond that.

Related

Error occurred during initialization of boot layer - javafx.controller in NetBeans

So, I'm attempting to build a simple JavaFX application in Apache Netbeans 11.1 using the non-modular from IDE instructions from this site:
https://openjfx.io/openjfx-docs/
I'm using JDK 13 and JavaFX 13.
The instructions work up until the point when they tell you to modify the VM options under Properties --> Run. I add the --module-path and --add-modules arguments as indicated, but still get an error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
C:\Users\BLAHBLAH\AppData\Local\NetBeans\Cache\11.1\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\BLAHBLAH\AppData\Local\NetBeans\Cache\11.1\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Ant set to Verbose using Tools-->Options-->Java-->Ant, verbosity level set to verbose.
Output with verbose:
Detected Java version: 13 in: D:\Programs\JavaStuff\jdk-13
Detected OS: Windows 10
Trying to override old definition of task java
Trying to override old definition of task input
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/extide/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/extide/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml from a zip file
Trying to override old definition of task javac
Trying to override old definition of task delete
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/profiler/ant/nblib/org-netbeans-modules-profiler-nbimpl.jar!/org/netbeans/modules/profiler/nbimpl/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/profiler/ant/nblib/org-netbeans-modules-profiler-nbimpl.jar!/org/netbeans/modules/profiler/nbimpl/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/profiler/ant/nblib/org-netbeans-modules-profiler-nbimpl.jar!/org/netbeans/modules/profiler/nbimpl/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/profiler/ant/nblib/org-netbeans-modules-profiler-nbimpl.jar!/org/netbeans/modules/profiler/nbimpl/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans-11.1/netbeans/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml from a zip file
parsing buildfile C:\Users\BLAHBLAH\AppData\Local\NetBeans\Cache\11.1\executor-snippets\run.xml with URI = file:/C:/Users/BLAHBLAH/AppData/Local/NetBeans/Cache/11.1/executor-snippets/run.xml
Project base dir set to: C:\Users\BLAHBLAH\AppData\Local\NetBeans\Cache\11.1\executor-snippets
Build sequence for target(s) `run' is [-init-paths, -init-macrodef-java-with-modules, -init-macrodef-java-with-unnamed-module, -init-macrodef-java-without-modules, run]
Complete build sequence is [-init-paths, -init-macrodef-java-with-modules, -init-macrodef-java-with-unnamed-module, -init-macrodef-java-without-modules, run, ]
-init-paths:
Override ignored for property "run.jvmargs"
Override ignored for property "work.dir"
Override ignored for property "application.args"
-init-macrodef-java-with-modules:
Skipped because property 'named.module.internal' not set.
-init-macrodef-java-with-unnamed-module:
creating macro call-java
-init-macrodef-java-without-modules:
Skipped because property 'modules.supported.internal' set.
run:
Executing 'D:\Programs\JavaStuff\jdk-13\bin\java.exe' with arguments:
'-Dfile.encoding=UTF-8'
'--module-path=D:\Programs\JavaStuff\javafx-sdk-13\lib\'
'--add-modules=javafx.controls,javafx.fxml'
'-classpath'
'D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx-swt.jar;D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx.base.jar;D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx.controls.jar;D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx.fxml.jar;D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx.graphics.jar;D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx.media.jar;D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx.swing.jar;D:\Programs\JavaStuff\javafx-sdk-13\lib\javafx.web.jar;C:\Users\BLAHBLAH\OneDrive\Documents\NetBeansProjects\HelloFX1\build\classes'
'--module-path'
'C:\Users\BLAHBLAH\OneDrive\Documents\NetBeansProjects\HelloFX1\build\classes'
'hellofx.HelloFX'
The ' characters around the executable and arguments are
not part of the command.
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
C:\Users\BLAHBLAH\AppData\Local\NetBeans\Cache\11.1\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\BLAHBLAH\AppData\Local\NetBeans\Cache\11.1\executor-snippets\run.xml:68: Java returned: 1
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:566)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:394)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:261)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:574)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:128)
BUILD FAILED (total time: 0 seconds)
Any ideas?
I appreciate the responses I received - they helped me to do more research and document a solution thoroughly for myself, my colleagues, and my students.
So, I hope that this will help others who are receiving similar errors and issues while trying to install OpenJDK, NetBeans 11.1, OpenJFX (Open JavaFX), and Scene Builder.
I uploaded a PDF and sample projects to which I refer in said PDF, to the following repository:
https://github.com/profjpbaugh/apache-netbeans-openjdk-openjfx
Thanks!

RobotFramework - ClassNotFound Exception when selenium org.openqa.selenium is added to my JavaLibrary

Please help me on this situation. I followed the below steps in Java and Added this jar file into Robot framework project. When executing the test, I received ClassNotFoundException.
Java Corrected Code:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.openqa.selenium.WebElement;
public class StoreElements{
public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";
public String storeTexts(List<WebElement> text){
for(WebElement theElement : text){
System.out.println("The Element class is:
"+theElement.getAttribute("class")+", text: " + theElement.getText());
}
return ((WebElement) text).getText();
}
}
Robot Framework Code:
*** Settings ***
Library Selenium2Library
Library keywords.kcc.StoreElements
*** Keyword ***
Get the customer Names
#{customers} get webelements xpath=//div[contains(#class,'name-column')]
store Texts #{customers}
IS that Something like i need to include Selenium2Library in Java Project rather than just selenium Or is it possible include Selenium2Library in Java?
The Exception that i received is,
[ ERROR ] Unexpected error: NoClassDefFoundError:
org/openqa/selenium/WebElement
java.lang.NoClassDefFoundError:
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at robot.utils.importer$py.import_$32(C:\jython2.7.0\Lib\site-
packages\robot\utils\importer.py:274)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\utils\importer.py)
at
robot.utils.importer$py._import_class_or_module$5(C:\jython2.7.0\Lib\site-
packages\robot\utils\importer.py:77)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\utils\importer.py)
at robot.utils.importer$py.import_class_or_module$4(C:\jython2.7.0\Lib\site-
packages\robot\utils\importer.py:74)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\utils\importer.py)
at robot.model.visitor$py.visit_suite$2(C:\jython2.7.0\Lib\site-
packages\robot\model\visitor.py:88)
at robot.model.visitor$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\model\visitor.py)
at robot.model.testsuite$py.visit$19(C:\jython2.7.0\Lib\site-
packages\robot\model\testsuite.py:161)
at robot.model.testsuite$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\model\testsuite.py)
at robot.model.itemlist$py.visit$11(C:\jython2.7.0\Lib\site-
packages\robot\model\itemlist.py:75)
at robot.model.itemlist$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\model\itemlist.py)
at robot.model.visitor$py.visit_suite$2(C:\jython2.7.0\Lib\site-
packages\robot\model\visitor.py:88)
at robot.model.visitor$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\model\visitor.py)
at robot.model.testsuite$py.visit$19(C:\jython2.7.0\Lib\site-
packages\robot\model\testsuite.py:161)
at robot.model.testsuite$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\model\testsuite.py)
at robot.utils.application$py._execute$10(C:\jython2.7.0\Lib\site-
packages\robot\utils\application.py:94)
at robot.utils.application$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\utils\application.py)
at robot.utils.application$py.execute_cli$5(C:\jython2.7.0\Lib\site-
packages\robot\utils\application.py:49)
at robot.utils.application$py.call_function(C:\jython2.7.0\Lib\site-
packages\robot\utils\application.py)
at runpy$py._run_code$9(C:\jython2.7.0\Lib\runpy.py:73)
at runpy$py.call_function(C:\jython2.7.0\Lib\runpy.py)
at runpy$py._run_module_as_main$14(C:\jython2.7.0\Lib\runpy.py:161)
at runpy$py.call_function(C:\jython2.7.0\Lib\runpy.py)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebElement
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 191 more
As suggested by Kootstra, added selenium-server-standalone-3.3.1 jar file and currently the RED.xml is as below, This time red line is not shown under keyword 'Store Texts'. The exception is thrown only when executing this. And not the longer exception message too.
Console Command:
Command: C:\jython2.7.0\bin\jython.exe -J-Dpython.path=C:\jython2.7.0\Lib\site-packages -J-cp .;C:\Program Files\Java\jdk1.8.0_121\lib;C:\Program Files\Java\jdk1.8.0_121\jre\lib;;.;C:\Java\Jars_KCC\GetElementText.jar;C:\jython2.7.0\selenium-server-standalone-3.3.1 -m robot.run -P C:\jython2.7.0\Lib\site-packages\Selenium2Library -i SmokeTest --listener C:\Users\CON_RT~1\AppData\Local\Temp\RobotTempDir3926709749247362236\TestRunnerAgent.py:63501:False -s KCC_Automation.TestSuites.TestResource -t KCC_Automation.TestSuites.TestResource.logon to kcc with valid credentials -t KCC_Automation.TestSuites.TestResource.navigate to customer's page -t KCC_Automation.TestSuites.TestResource.display customer names -t KCC_Automation.TestSuites.TestResource.stop testing C:\Java\Workspace\KCC_Automation
Suite Executor: Robot Framework 3.0.2 (Jython 2.7.0 on java1.8.0_121)
I created new project, then added only the 'c:\jython2.7.0\selenium-server-standalone-3.3.1\' into classpath along with Selenium2library and own java library. I also tried adding .jar at the end of the jar file. It still has exception. But one thing is that now it stopped showing ;;.;
Here is the console command now,
Command: C:\jython2.7.0\bin\jython.exe -J-Dpython.path=C:\jython2.7.0\Lib\site-packages -J-cp .;C:\Java\JarsKCC\GetElementList.jar;C:\jython2.7.0\selenium-server-standalone-3.3.1.jar -m robot.run -P C:\jython2.7.0\Lib\site-packages\Selenium2Library -i SmokeTest --listener C:\Users\CON_RT~1\AppData\Local\Temp\RobotTempDir9154227905398549031\TestRunnerAgent.py:54485:False -s KCC_Automation.TestSuites.TestResource -t KCC_Automation.TestSuites.TestResource.logon to kcc with valid credentials -t KCC_Automation.TestSuites.TestResource.navigate to customer's page -t KCC_Automation.TestSuites.TestResource.display customer names -t KCC_Automation.TestSuites.TestResource.stop testing C:\Java\Workspace\KCC_Automation
Suite Executor: Robot Framework 3.0.2 (Jython 2.7.0 on java1.8.0_121)
This time the exception is different. ClassCastException: org.python.core.PyObjectDerived cannot be cast to org.openqa.selenium.WebElement
The error is in my view quite straight forward: [ ERROR ] Unexpected error: NoClassDefFoundError: org/openqa/selenium/WebElement it is missing this class. This is a class found in the regular selenium-server-standalone-x.x.x.jar.
In the past couple of days you've asked some questions in context of RED and Jython, and I'm going to assume that this is your development environment. That being said, if it happens to be different the steps would still apply but applied differently.
I've taken your java class and converted it to a Jar file. In RED I've created a robot project and added it as a Library file. In this StackOverflow response I've detailed the process step-by-step.
Because the robot script wasn't complete, I've complemented it so that it now looks like this:
*** Settings ***
Library StoreElements
Library Selenium2Library
*** Test Cases ***
Get the customer Names
#{customers} Get Webelements xpath=//div[contains(#class,'name-column')]
Store Texts ${customers}
The addition of the Libraries is needed to ensure the keywords are recognized and that means the libraries are loaded correctly.
Because the new Jar file refers to the Selenium Server class it needs to be able to access it. This requires that this class is part of the class path. In RED this can be achieved by adding the selenium-server-standalone-x.x.x.jar to the class path in the RED.xml project file.
This should then look like this:
Although this robot file will fail when run, the generated command might be of some interest if you want to specify the java path from the command line when working with Jython and Robot Framework in RED:
C:\jython2.7.0\bin\jython.exe
-J-Dpython.path=C:\jython2.7.0\Lib\site-packages
-J-cp
.;
C:\Eclipse\Workspace\JavaSelenium\ExampleLibrarySelenium.jar;
C:\Eclipse\Workspace\ExampleJavaSelenium\selenium-server-standalone-3.3.1.jar
-m robot.run
-P C:\jython2.7.0\Lib\site-packages\Selenium2Library
--listener C:\Users\User\AppData\ ... \TestRunnerAgent.py:54540:False
-s JavaSelenium.Example
C:\Eclipse\Workspace\JavaSelenium
In the above formatted command, the class path is defined by the -J-cp argument. The added custom Java Robot library ExampleLibrarySelenium.jar and the additionally required dependency selenium-server-standalone-3.3.1.jar complement the standard . which refers to the folder where jython.exe is located.
Although adding the jar files to the existing . folder would have worked too, it is better to add the required files per project, in order to ensure that the right version is added but also to allow for local experimentation.

Apktool doesnt compile properly via command line

I am able to decompile the file using "advanced apktool" but when i use apktool alone via command line I get this error:
I: Baksmaling... I: Loading resource table... Exception in thread "main" brut.androlib.AndrolibException: Could not decode arsc file at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:55) at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:315) at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:50) at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:43) at brut.androlib.Androlib.getResTable(Androlib.java:44) at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:148) at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98) at brut.apktool.Main.cmdDecode(Main.java:128) at brut.apktool.Main.main(Main.java:65) Caused by: java.io.IOException: Expected: 0x001c0001, got: 0x00000000 at brut.util.ExtDataInput.skipCheckInt(ExtDataInput.java:48) at brut.androlib.res.decoder.StringBlock.read(StringBlock.java:45) at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:97) at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:82) at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48) ... 8 more" My apk does have a res folder i can see it using dexindexor app on my phone and it decompiled using other decompilers (that use apktool) its just apktool doesn't decompile it on its own properly.
Its the same when i try a different comnputers. I'm using winxp 32 jre 1.7, win7 64 jre 1.8.
Why is this happenning and how do I fix it?

pig aws emr jython serialization error

I am trying to run a trivial Python UDF in Pig on Amazon EMR and it throws a java serialization error:
java.io.IOException: Deserialization error: could not instantiate 'org.apache.pig.scripting.jython.JythonFunction' with arguments '[/tmp/pig4877832484731242596tmp/simple.py, aprs]'
I've searched here and elsewhere and seen somewhat related questions and solutions posted, but none of the solutions seem to apply, including one post over a year ago that seemed to indicate this was working OK with Pig 0.9.1 on Amazon EMR.
$ pig --version
Apache Pig version 0.9.2-amzn (rexported)
compiled Aug 06 2012, 20:34:29
$ hadoop version
Hadoop 1.0.3
Here's my trivial python UDF:
#/usr/bin/python
#outputSchema("data:chararray")
def aprs(l):
return l
And here's the pig script invocation that shows the UDF is loaded and the #outputSchema did the right thing:
grunt> Register 's3n://n2ygk/simple.py' using jython as myudf;
grunt> raw = LOAD 's3n://aprs-is/small-sample.log' USING TextLoader as (line:chararray);
grunt> cooked = LIMIT raw 1000;
grunt> aprs = FOREACH cooked GENERATE FLATTEN(myudf.aprs(line));
grunt> DESCRIBE aprs;
aprs: {data: chararray}
grunt> dump aprs;
Any suggestions?
The short answer is to download, build and use Pig 0.11.1 as described with this post on the AWS forum. Once I did this, the Python UDF code "just worked".
I first did this naively by using the above-referenced script that downloads and builds Pig 0.11.1. I assumed this was likely overkill to build pig from scratch since I've been reading up more on Pig versions and believe that 0.11.1 is already available via --pig-versions. (Although the doc doesn't list 0.11.1, the pig installer script does include it.) I've used the following command to test using the EMR-distro of pig-0.11.1:
./elastic-mapreduce --create --name 'Pig11 2013-06-03-21:35:24' --alive \
--num-instances 1 --instance-type m1.small --pig-interactive \
--pig-versions 0.11.1 \
--bootstrap-action s3n://us-west-2.elasticmapreduce/bootstrap-actions/configurations/latest/memory-intensive \
--bootstrap-name 'memory intensive'
Unfortunately, this throws the following error which appears to perhaps be related to java version 1.6 vs. 1.7:
hadoop#ip-10-253-41-55:~$ pig
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/pig/Main : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.hadoop.util.RunJar.main(RunJar.java:180)
hadoop#ip-10-253-41-55:~$ hadoop version
Hadoop 1.0.3
When I retested the above without specifying --pig-versions 0.11.1 it turns out that only 0.9.2 is installed in response to the default value for --pig-versions latest.
I see from (s3://us-west-2.elasticmapreduce/libs/pig/pig-script) that Pig 0.11.1 and hadoop 1.0.3 require java 7 whereas 0.9.2 requires hadoop 1.03 with java 6. I'm guessing that somehow java 7 did not get installed.
If someone can straighten me out on what I'm doing wrong, I'd really appreciate it. Otherwise, I'll live with the workaround of downloading and building it as it wastes a little time but does work.

How to run TestNG suite from command line

I would like to run TestNG Suite from command line on Linux. I'm using eclipse to run test, but I have problem with command line. I know that I need to have testng.jar and I have it in /home/karcio/dev/testng-6.4.jar, location my suite xml is /home/karcio/git/java-test-automation/Automation/test-output/Default suite/TestSuite.xml . Commands what I tried,
set classpath /home/karcio/dev/testng-6.4.jar
cd /location to my suite xml file: java org.testing.TestNG TestSuite.xml
This is error what I see:
Exception in thread "main" java.lang.NoClassDefFoundError: org/testing/TestNG
Caused by: java.lang.ClassNotFoundException: org.testing.TestNG
I'm new in those path and classpath, I'm little bit confusing :(
Thank you
Little update,
I think I did all good, now when I put to terminal: java org.testng.TestNG Test.xml
I've got this error:
Exception in thread "main" org.testng.TestNGException: No sourcedir
was specified at org.testng.TestNG.checkConditions(TestNG.java:1170)
at org.testng.TestNG.privateMain(TestNG.java:1010) at
org.testng.TestNG.main(TestNG.java:997)
all path are exported, so maybe this is wrong version of testng.jar, tried with versions 5.5, 6.4, 6.5, 6.6, 6.7 but I think only version 5.5 is working,
There is a typo in the class package
org.testing.TestNG
should be
org.testng.TestNG
(There no i in the .testng. part)
http://testng.org/javadoc/org/testng/TestNG.html