简体   繁体   English

在RIDE中导入Java库

[英]Import Java library in RIDE

I'm trying to use a java library in RIDE. 我正在尝试在RIDE中使用java库。 I found a good tutorial( https://blog.codecentric.de/en/2012/06/robot-framework-tutorial-writing-keyword-libraries-in-java/ ) I follow it, but when the time comes to import and use the java library ( Database Library)in RIDE. 我找到了一个很好的教程( https://blog.codecentric.de/en/2012/06/robot-framework-tutorial-writing-keyword-libraries-in-java/ )我遵循它,但是什么时候进入并在RIDE中使用java库(数据库库)。 It fails. 它失败。 When I look the page with my different imports, the java library is written in red and not in black as the others. 当我用不同的导入来查看页面时,java库用红色写,而不是用其他的黑色写。

And when I try to run with Jybot, I have the well-known message : [ ERROR ] Error in file 'C:\\Users\\XXXXXX\\Documents\\Robot_Test\\implementation\\DB_Test\\Example.html': Importing test library 'org.robot.database.keywords.DatabaseLibrary' failed: ImportError: No module named robot 当我尝试使用Jybot运行时,我有一个众所周知的消息:文件'C:\\ Users \\ XXXXXX \\ Documents \\ Robot_Test \\ implementation \\ DB_Test \\ Example.html'中的[错误]错误:导入测试库'组织。 robot.database.keywords.DatabaseLibrary'失败:ImportError:没有名为robot的模块

I follow every line of the tutorial, even the with the set CLASSPATH. 我按照教程的每一行,甚至是设置CLASSPATH。

Any idea ? 任何想法 ? ( I know that this library exist in Python, but I want to write my own java libraries ^^) Thanks (我知道这个库存在于Python中,但我想编写自己的java库^^)谢谢

This worked for me using: 这对我有用:

  • Jython 2.7b4 Jython 2.7b4
  • Robotframework 2.8.7 Robotframework 2.8.7
  • Ride 1.3 乘坐1.3

Create Lib and compile it (you do not need to jar it) 创建Lib并编译它(你不需要jar它)

Directory structure is 目录结构是

run_ride.sh
libs/DemoLib.class
tests/DemoLibTest.txt

Excerpt from tests/DemoLibTest.txt: 摘自tests / DemoLibTest.txt:

* Settings
Library           ../libs/DemoLib.class

* Test Cases
DemoLibTest
    Print Demo

Start Ride, switch to tab "Run", choose Execution Profile: jybot , press Start, output is: 开始骑行,切换到“运行”选项卡,选择Execution Profile: jybot ,按开始,输出为:

Starting test: tests.DemoLibTest.DemoLibTest
20150304 19:13:20.321 :  INFO : ---------- Demo ---------------

To avoid confusion put this line 为了避免混淆这一行

echo $CLASSPATH

in your Ride startup script in order to ensure that your library is really imported. 在您的Ride启动脚本中,以确保您的库真正导入。 By the way, in my Ride the import is also marked red. 顺便说一下,在我的Ride中,导入也标记为红色。 Sometimes restarting Ride might help. 有时重启Ride可能有所帮助。 But the colour does not mean anything, if your settings are correct. 但如果您的设置正确,颜色并不意味着什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM