如何运行Java文件?
中有一个 java 程序,
文件夹Downloads/jason/src/demo/de/l3s/jason/testfile.java
我可以用 javac testfile.java
编译它(同时在该目录中) 生成testfile.class
。
但我无法通过输入 java testfile 来运行该文件 如果我设法运行该文件,它无法找到该文件的任何组件。
testfile.java
包含
package de.l3s.jason.demo;
import java.net.URL;
import de.l3s.jason.extractors.ArticleExtractor;
public class testfile
几行代码。
我如何告诉 Java 在哪里寻找这些组件?
我已经将几个 jar 文件添加到类路径中(根据文档),方法是将它们直接复制到 home/usr/lib/jvm/java/jre/lib/ext
中除此之外,类路径可以正常工作“java”和“javac”可以在任何地方工作。
我也无法让它在 Windows 上运行,这就是我切换到 Linux 的原因。
There is a java program in the folder
Downloads/jason/src/demo/de/l3s/jason/testfile.java
I can compile it with javac testfile.java
(while in that directory)
Resulting in testfile.class
.
But I cannot run this file by typing java testfile
If I manage to run the file, it cannot locate any components of the file.
The testfile.java
contains
package de.l3s.jason.demo;
import java.net.URL;
import de.l3s.jason.extractors.ArticleExtractor;
public class testfile
And then a couple of lines of code.
How do I tell Java where to look for these components?
I have added several jar files to the classpath (per the documentation) by copying them directly into home/usr/lib/jvm/java/jre/lib/ext
Aside from that, the classpath works fine with "java" and "javac" working from anywhere.
I couldn't get this to work on Windows either, which is why I switched to linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试
但首先确保它包含
try
But first make sure it contains a
尝试:
Try:
请尝试
java de.l3s.jason.demo.testfile
。也许您需要向类路径添加更多 jar 文件,因此请在此处输入结果。
Please try
java de.l3s.jason.demo.testfile
.Maybe you need to add more jar-Files to the classpath then that, so please enter the result here.
假设您已经编译了源tred中的所有类,并且编译后的类文件存储在.java文件所在的目录中,那么您需要使用以下命令。
请注意使用 -cp 开关来指定类路径的根目录(包结构开始的位置)。
如果类需要其他库,则需要将它们包含在
-cp
开关中:(假设您是在 Unix 风格的操作系统上,您需要使用
;
作为路径分隔符,当然还需要使用反斜杠而不是正斜杠)Assuming you have compiled all classes within the source tred and the compiled classfiles are stored in the directory where your .java file is, then you need to use the following command.
Note the usage of the -cp switch to specify the classpath's root directory (where the package structure starts)
If the classes need additional libraries, you need to include them in the
-cp
switch:(Assuming you are on a Unix style operating system. On Windows you need to use
;
as the path separator and of course a backslash instead of a forward slash)