由于外部库,Java可以在终端中编译
我在Ubuntu 22.04尝试在终端运行我的代码。 该程序在VSCODE中也没有问题,也可以运行多个实例。 该程序由六个类文件组成。
当我尝试使用终端运行它时,就会发生麻烦。编译Java文件时 使用Javac
它在我使用外部库的地方显示错误。
如果我使用VSCODE编译并以终端运行类文件,则会获得以下错误java.lang.classnotfoundexception
这会导致我问题,因为我也应该对该程序进行扩展。
I'm on Ubuntu 22.04 trying to run my code in the terminal.
The program works without problems in VScode, also when running multiple instances.
The program is consisted of six class files.
The trouble occurs when I try and run it with terminal. When compiling the java file
with javac
it shows errors at places where I use the external libraries.
If I compile it with VScode and run the class file in terminal, I get the following error java.lang.ClassNotFoundException
This is causing me problems since I'm also supposed to dockerize the program.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在
street.json
文件“ java.project.outputpath”中添加以下代码:“ bin”
,这将是运行Java代码时的
bin
文件夹中VS代码生成的.class
文件。您可以使用
cd
命令输入文件目录后使用Java命令。You can add the following code in your
setting.json
file"java.project.outputPath": "bin"
,This will be the
.class
file generated by VS Code in thebin
folder of the same directory when running the Java code.You can use the java command after entering the file directory with the
cd
command.这通常表明您要编译程序的类路径不包括库的正确路径。假设您的库是JAR文件,您的
javac
命令应该看起来像这样:其中
libs/
是您库的相对路径,srcs/
是您自己的Java文件的相对路径。当您运行程序时,请确保您的类路径既包含库的位置又包括类文件的位置(在这种情况下是当前目录):
This generally indicates that the class path with which you're compiling your program does not include the correct paths to your libraries. Assuming your libraries are jar files, your
javac
command should look something like this:where
libs/
is the relative path to your libraries andsrcs/
is the relative path to your own java files.And when you run the program, make sure your class path includes both the locations of your libraries and the location of your class files (which in this case would be the current directory):