My automation group recently standardized using standalone version of
jython instead of standard, but standalone version does not do java
package caching, which makes it impossible to load java libraries.
Has anybody been able to solve this problem? Or does robot framework
support standalone jython?
My command line looks something like this:
java -classpath path/to/jar /path/robot/runner.py [options]
data_sources
Particular example, is using trying to import javalib in robot specs
(.tsv) settings section
Library org.robotframework.javalib.library.AnnotationLibrary com/
basistech/grail/lemmatization/**.class
Failure is:
Importing test library
'org.robotframework.javalib.library.AnnotationLibrary' failed:
ImportError: No module named robotframework
I know for sure, this works with standard jython installation, but it
is not an option I can use now.
Any help in this matter will be greatly appreciated
Are you sure it's not possible to use Java libraries from the
standalone Jython? I would be highly surprised about it because using
Java is the biggest reason to use Jython.
> My command line looks something like this:
>
> java -classpath path/to/jar /path/robot/runner.py [options]
> data_sources
>
> Particular example, is using trying to import javalib in robot specs
> (.tsv) settings section
>
> Library org.robotframework.javalib.library.AnnotationLibrary com/
> basistech/grail/lemmatization/**.class
>
> Failure is:
>
> Importing test library
> 'org.robotframework.javalib.library.AnnotationLibrary' failed:
> ImportError: No module named robotframework
>
> I know for sure, this works with standard jython installation, but it
> is not an option I can use now.
I'm not a Java expert myself, but I have enough experience to know
that most Java problems like this are somehow related to the
classpath. Are you sure you have AnnotationLibrary in classpath in
this case?
We have actually discussed packaging Robot Framework and Jython into a
standalone jar file that could be used without Python. This isn't too
high on the priority list for the core development team, but if
someone else is interested to look at this we are highly interested.
Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
2010/3/20 Shark <bug...@gmail.com>:
> On Fri, Mar 19, 2010 at 5:12 PM, Pekka Klärck <pekka....@gmail.com>
> wrote:
>> 2010/3/19 pi <bug...@gmail.com>:
>> >
>> > My automation group recently standardized using standalone version of
>> > jython instead of standard, but standalone version does not do java
>> > package caching, which makes it impossible to load java libraries.
>> >
>> > Has anybody been able to solve this problem? Or does robot framework
>> > support standalone jython?
>>
>> Are you sure it's not possible to use Java libraries from the
>> standalone Jython? I would be highly surprised about it because using
>> Java is the biggest reason to use Jython.
>>
> Yes, I am sure of it - jython standalone version ignores classpath and
> requires you to import each java package separately through interpreter
Sorry, I don't really get this. What do you mean with importing
separately through the interpreter? As I wrote, using Java is the main
use case of Jython, and I'm sure there is a way to get this done.
>> > My command line looks something like this:
>> >
>> > java -classpath path/to/jar /path/robot/runner.py [options]
>> > data_sources
>> >
>> > Particular example, is using trying to import javalib in robot specs
>> > (.tsv) settings section
>> >
>> > Library org.robotframework.javalib.library.AnnotationLibrary
>> > com/
>> > basistech/grail/lemmatization/**.class
>> >
>> > Failure is:
>> >
>> > Importing test library
>> > 'org.robotframework.javalib.library.AnnotationLibrary' failed:
>> > ImportError: No module named robotframework
>> >
>> > I know for sure, this works with standard jython installation, but it
>> > is not an option I can use now.
>>
>> I'm not a Java expert myself, but I have enough experience to know
>> that most Java problems like this are somehow related to the
>> classpath. Are you sure you have AnnotationLibrary in classpath in
>> this case?
>
> jar containing AnnotationLibrary is in the path.
> Another reason I know this is not a classpath problem from me is because all
> this works fine with standard version of jython
Are you starting everything exactly the same way? As I wrote I'm not a
Java expert, but I know that it's pretty strict on how you need to set
the classpath. The specified classpath is, for example, ignored if you
use -jar option, and it could also be that CLASSPATH environment
variable isn't processed when you use -classpath option.
>> We have actually discussed packaging Robot Framework and Jython into a
>> standalone jar file that could be used without Python. This isn't too
>> high on the priority list for the core development team, but if
>> someone else is interested to look at this we are highly interested.
>
> This would be great!!! If I would know how I would help.
It would help if someone studied how packaging everything together
could be done in practice. This stuff ought to be explained pretty
well in the Jython Book (http://jythonbook.com) and especially in the
Jython/Java integration chapter:
http://jythonpodcast.hostjava.net/jythonbook/en/.99/JythonAndJavaIntegration.html
Cheers,
.peke
2010/3/22 Shark <bug...@gmail.com>:
>
>
> On Mon, Mar 22, 2010 at 4:30 AM, Pekka Klärck <pekka....@gmail.com>
> wrote:
>>
>> [Added rf-users back to Cc.]
>>
>> 2010/3/20 Shark <bug...@gmail.com>:
>> > On Fri, Mar 19, 2010 at 5:12 PM, Pekka Klärck <pekka....@gmail.com>
>> > wrote:
>> >> 2010/3/19 pi <bug...@gmail.com>:
>> >> >
>> >> > My automation group recently standardized using standalone version of
>> >> > jython instead of standard, but standalone version does not do java
>> >> > package caching, which makes it impossible to load java libraries.
>> >> >
>> >> > Has anybody been able to solve this problem? Or does robot framework
>> >> > support standalone jython?
>> >>
>> >> Are you sure it's not possible to use Java libraries from the
>> >> standalone Jython? I would be highly surprised about it because using
>> >> Java is the biggest reason to use Jython.
>> >>
>> > Yes, I am sure of it - jython standalone version ignores classpath and
>> > requires you to import each java package separately through interpreter
>>
>> Sorry, I don't really get this. What do you mean with importing
>> separately through the interpreter? As I wrote, using Java is the main
>> use case of Jython, and I'm sure there is a way to get this done.
>
> I am sure there is a way to get it done and I would be very interested to
> find out how is java used with standalone jython.
> Is there a use case of how to execute robot tests with standalone jython? My
> claim is that there is a difference in executions and I have not being able
> to figure out the magic to succeed through robot test case execution
> My command looks something like this
> java -classpath [classpath with all jars test libraries including standalone
> jython jar] org/python/util/jython /path/to/runner.py [options] DATA
> However,
> none of the jar are being imported (cached) by package manager from jython
> and so executing robotframework will report setting error, that some library
> cannot be imported
> In my case that library is javalib_core and is specified in test spec in
> settings section:
> Library org.robotframework.javalib.library.AnnotationLibrary
> /path/to/my/classes
> To workaround this problem it was suggested by some members if my team to
> use PythonInterpreter to import java packages:
> http://jython.sourceforge.net/docs/javadoc/org/python/util/PythonInterpreter.html
> This is an example what do I mean by separate interpreter (of course this
> did not work ;))
>
> Properties postProperties = new Properties();
>
> postProperties.put("python.home", jythonHome);
>
> postProperties.put(PySystemState.PYTHON_CACHEDIR,
> System.getProperty("java.io.tmpdir"));
>
> postProperties.put(PySystemState.PYTHON_CACHEDIR_SKIP, "false");
>
> PySystemState.initialize(null, postProperties);
>
> PySystemState pySystemState = new PySystemState();
>
> ClassLoader loader = getClass().getClassLoader();
>
> System.out.println(loader);
>
> // this section tries to import javalib package to do the same thing what
> jython-standard was doing underneath
>
> PythonInterpreter pi = new PythonInterpreter(new PyStringMap(),
> pySystemState);
>
> StringReader reader = new StringReader("import
> org.robotframework.javalib.library");
>
> PyCode autogenCode = pi.compile(reader);
>
> pi.exec(autogenCode);
>
> // this section tries to execute runner.py script inside the python
> interperter
>
> InputStreamReader genReader = new InputStreamReader(new
> FileInputStream(runner_script), "utf-8");
>
> autogenCode = pi.compile(genReader);
>
> pi.exec(autogenCode);
> I am not using jar option (calling it directly java -classpath [..]
> org.python.util.jython ....)
I don't have time to try to reproduce this, but a fast search using
terms "jython standalone classpath" revealed that there really seems
to be issues related to scanning jar files when using the standalone
Jython. You can try the search yourself, but especially these bug
reports provide some interesting information:
http://bugs.jython.org/issue1422
http://bugs.jython.org/issue1778514
The latter one of these reports has actually been submitted by Juha
from our team 2,5 years ago, so apparently this isn't the first time
this problem is encountered with Robot Framework. The problem is
reported against Jython 2.2, but based on the former report there are
similar issues in 2.5 too.
The good news is that the reply by Charlie Groves gives me an idea
what you could try as a workaround. Instead of using CLASSPATH
environment variable to specify the jar files containing libraries,
pass them to RF using the --pythonpath command line option. RF will
then add those jars to sys.path internally, and according to Charlie
that ought to work.
Please report back if the proposed workaround actually works or you
find some other solution. We probably should also document this
problem in the installation instructions or somewhere else.