[英]Where to install library for Java on Ubuntu command line
I'm trying to get the Charva tutorial to work, but I don't think I'm installing it correctly. 我正在尝试运行Charva教程,但是我认为我没有正确安装它。 I added the .jar files to /jre/lib/ext, but I get this error when I try to run the tutorial file:
我将.jar文件添加到/ jre / lib / ext,但是在尝试运行教程文件时出现此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: Tutorial (wrong name: tutorial/java/Tutorial)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Am I supposed to be running something else when I compile or am I installing the library the wrong way? 我在编译时应该运行其他内容吗?还是安装库的方式错误?
I suggest you build and run your program in your IDE. 我建议您在IDE中构建并运行程序。
Once you have a working program you can build a JAR and when you specify it on the command line with 有了工作程序后,您可以构建一个JAR,并在命令行上使用以下命令指定它时
java -cp {path-to-my-jar}.jar mypackage.MyClass
you can put the JAR where ever you like. 您可以将JAR放在您喜欢的任何位置。
You can add the .jar
files to the classpath using: 您可以使用以下命令将
.jar
文件添加到类路径中:
java -cp "Charva.jar" main.Class
If you need to add multiple jars, or you want it to be better structured in folders, put the jars under lib
which is the common thing to do, and use: 如果需要添加多个jar,或者希望将其更好地放在文件夹中,请将这些jar放在
lib
下,这很常见,然后使用:
java -cp "lib/*.jar" main.Class
If you're using and IDE, tag the question with the specific IDE to get specific instructions for your IDE. 如果您使用的是IDE,请使用特定的IDE标记问题,以获取有关IDE的特定说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.