从依赖于外部库的终端运行Java [英] run java from terminal that depend on external libraries

查看:61
本文介绍了从依赖于外部库的终端运行Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多东西,但是还没有找到解决方案.

I've read around a lot but haven't been able to find a solution yet.

我正在使用 lwjgl ,它需要2个jar和一个本机库来运行: lwjgl.jar lwjgl_util.jar 和本地人图书馆.无论如何,我已经尽我所能尝试了所有方法,现在我正在尝试使用以下命令:

I'm using lwjgl, it needs 2 jars and a native library to run: lwjgl.jar, lwjgl_util.jar and the natives library. I've tried this in every way i could think of, anyway, I'm trying with a command like this at the moment:

java - Djava.library.path="libs/natives/" -cp libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest.class

但是我尝试通过各种方式得到:

but in every way i try, i get:

Exception in thread "main" java.lang.NoClassDefFoundError: DisplayTest/class
Caused by: java.lang.ClassNotFoundException: DisplayTest.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: DisplayTest.class. Program will exit

哦,值得一提的是,我正在Linux终端上工作.另外,我使它在日食中运行得非常好,所以我真的不明白这里发生了什么.

Oh and it might be worth to mention that I'm working on a linux terminal. Also, i get this to run perfectly fine in eclipse so I can't really understand whats up here.

推荐答案

首先,您只需要将类名传递给java:

First off, you just need to pass the class name to java:

java -Djava.library.path="libs/natives/" 
     -cp libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest

(可读性的换行符)

我会尝试以下操作:

1)使用CLASSPATH环境变量,如:

1) Use the CLASSPATH enviroment variable, as in:

  CLASSPATH=.:/path/to/lwjgl/lwjgl.jar:/path/to/lwjgl/lwjgl_util.jar 
  export CLASSPATH

注意类路径开头的点 (.);

Notice the dot (.) at the very beginning of the classpath;

2)运行您的Java应用程序:

2) Run your java application:

  java -Djava.library.path="libs/natives" DisplayTest

如果这可行,请将上面的命令添加到Shell脚本中.祝你好运!

If this works, add the commands above to a shell script. Good luck!

这篇关于从依赖于外部库的终端运行Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆