0

I did some robot framework python examples with pybot, and referenced .py files as my library files. The folder structure I used was test/lib/myLib.py and test/test/myTest.robot, where /test was at the same level as the /src folder in my project in eclipse.

I then tried to do similar things with a java project using jython. I have /test/test/myTest.robot which imports the library ../lib/myLib.java. I even tried importing this file using RIDE, but it always shows up as red text, meaning the import failed. The specific message I get from using jybot on the command line is:

"Importing test library 'C:\Users\cody\git\myProject\test\lib\myLib.java' failed: ImportError: No module named myLib"  

I read that I might need to add it to classpath, and I think in order to do so, I need to make it a .jar file. I'd rather not do all that if possible to just leave it as a .java file. I attempted to add the lib folder to the build path... By that I mean I added the /test/lib folder to the "Source folders on build path". I also exported the darn thing as a jar and added that as a library. All this was done from the project properties in Eclipse.

I'm pretty stuck... any ideas how to get this working?

1 Answer 1

1

Java being a compiled language, you need to compile your java Class before importing it with RobotFramework.

Normally, Eclipse would do that for you, and put the resulting .class files inside a bin repository. If not, you can issue the javac path/to/file.java command, and move the resulting .class file where you want it (somewhere referenced by the classpath.

From within the .robot file, you should have the line Library test/lib/myLib, without neither .java nor .class at the end.

Sign up to request clarification or add additional context in comments.

14 Comments

Thanks for your answer. It sounds like I need to figure out why eclipse hasn't taken the file, compiled it, and put it in the bin directory or on the classpath. Is this because it is outside my /src directory in the project? Any idea how to get eclipse to do the work for me so that other users will have to do less manually stuff?
I am by no way an Eclipse expert, but I think you need to declare your source directories, in your project. Maybe you did not declare your test directory as a source, in your project's preferences? Like described there
Hmm, I believe I've already tried this, as I mentioned in my question, but I'll delve a little deeper into it a second time to see if it is in fact what I am looking for as a solution. I'll let you know.
Also, did you setup the option to build automatically (project -> Build automatically)? This should trigger the build on save.
You can download the .jar from Maven central, and put it in a lib folder in your project. Then, you call is as I described above, java -cp "lib/robotframework-2.8.7.jar;bin/" org.robotframework.RobotFramework myTest.robot
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.