简体   繁体   English

如何将.jar文件添加到Rhino的类路径中?

[英]How do I add a .jar file to Rhino's classpath?

I am scripting Java via Rhino, and I would like to use the JCodec library. 我正在通过Rhino编写Java脚本,我想使用JCodec库。 I put the jcodec-0.1.9.jar file in the same directory, and I added it via -cp on the command-line. 我将jcodec-0.1.9.jar文件放在同一目录中,并通过-cp在命令行中添加了它。 The command to invoke Rhino looks like: 调用Rhino的命令如下:

java -cp "rhino-1.7.7.1.jar;jcodec-0.1.9.jar;." org.mozilla.javascript.tools.shell.Main -opt 9 js/main.js %* 

However, the library doesn't load at all, since all of its classes remain undefined. 但是,该库根本不会加载,因为其所有类均未定义。 For example, running: 例如,运行:

print(java.lang.Class.forName('org.jcodec.api.awt.SequenceEncoder'))

throws a ClassNotFoundException , while it doesn't for say, 'javax.swing.JFrame' . 抛出ClassNotFoundException ,而不是'javax.swing.JFrame'

I feel like I'm not including it correctly, but everywhere I've looked, this seems to be the way. 我觉得我没有正确包含它,但是无论从哪里看,似乎都是这样。 Anyone have any suggestions? 有人有什么建议吗?

try the following to make sure that the current directory is in your classpaht: 请尝试以下操作以确保当前目录在您的classpaht中:

java -cp ".\rhino-1.7.7.1.jar;.\jcodec-0.1.9.jar;." org.mozilla.javascript.tools.shell

Note: if you're on UNIX change the .\\ to ./ and the ; 注意:如果您使用的是UNIX,请将。\\更改为./,然后将;更改为。 to : 至 :

UPDATED: 更新:

The class you are trying to reference does not have an 'awt' in it. 您尝试引用的类中没有'awt'。 Should be: 应该:

  org.jcodec.api.SequenceEncoder

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

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