简体   繁体   English

通过 VSC 加载 Java 库?

[英]Load Java libraries via VSC?

I'm very beginner in Java and for that reason I'm having issues to understand how the imports work... The problem is to import the Ini library to a project in VSC.我是 Java 的初学者,因此我在理解导入如何工作时遇到问题……问题是将 Ini 库导入 VSC 中的项目。 I've download the jar from ini4j and place it in the folder Referenced Libraries of the project and a.vscode and lib folders were created.我从ini4j下载了 jar 并将其放在项目的引用库文件夹中,并创建了 a.vscode 和 lib 文件夹。 In the class file I try to import it: import org.ini4j.*;在 class 文件中,我尝试导入它: import org.ini4j.*; and use it.并使用它。 But when I compile the code it seems like it doesn't find it as you can see here .但是当我编译代码时,它似乎没有找到它,正如您在此处看到的那样 Before asking the question I did some research and tried to follow tutorials that said to introduce in .vscode\settings.json this code:在问这个问题之前,我做了一些研究,并尝试按照在.vscode\settings.json中介绍此代码的教程进行操作:

"java.project.referencedLibraries": [
    "library/**/*.jar"
    "ini4j-0.5.4/ini4j-0.5.4.jar",
    "ini4j-0.5.4/ini4j-0.5.4-jdk14.jar"
]

Do you have a solution for my problem please?请问您有解决我的问题的方法吗? Is my import poorly done or how I use the library in the call?我的导入做得不好还是我如何在调用中使用库?

It seems like VSC recognises the library but not Windows...似乎 VSC 可以识别该库,但不能识别 Windows ...

The problem is the way you are compiling the program.问题是您编译程序的方式。 If you want to compile it from the terminal and then run it, you need to specify what libraries you are using.如果你想从终端编译它然后运行它,你需要指定你正在使用的库。 I would recommend you to add Java extension to you VS code, but if you insist on compiling it from cmd you need to do:我建议您将 Java 扩展添加到您的 VS 代码中,但如果您坚持从 cmd 编译它,您需要这样做:

For Windows machine适用于Windows机器

javac -cp ".;first.jar;second.jar;third.jar" *.java

And run it as并运行它

java -cp ".;first.jar;second.jar;third.jar" Main.java

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

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