英文:
VSCode: How to import a jar file into your java project?
问题
以下是翻译好的部分:
我对Java还不太了解,在我大学的课程中,我的教授给了我们以下的指示:
-
下载附加的 .jar 文件。
-
在 Eclipse 中创建一个 Java 项目。项目的名称不重要。
-
在项目名称上右键点击,然后选择 ‘导入’。
-
在 ‘常规’ 中选择 ‘存档文件’ 并点击下一步。
-
点击 ‘浏览’ 以选择之前已经下载好的 a1.jar 文件。
-
点击 ‘完成’。
如果所有步骤都正确执行,你应该在 ‘src’ 下看到 ‘Assignment1’,并且在项目下看到 Junit5。如果 ‘Assignment1’ 不在 ‘src’ 下,可以将其拖放到 ‘src’ 文件夹中。
这个指示是基于 Eclipse 的,但我正在使用 VSCode,到目前为止,我已经通过使用 Java 扩展来成功运行 Java。
我尝试过一些建议,来自于 https://stackoverflow.com/questions/50232557/visual-studio-code-java-extension-howto-add-jar-to-classpath,但是并没有成功(基本上在 src 下没有 Assignment1)。
是否有解决这个问题的方法,或者我应该简单地切换到 Eclipse。
我的项目文件夹结构
英文:
So I'm pretty much new to Java and in one of my university courses, my prof gave us the following instruction:
-
Download the attached .jar file.
-
Create a java project in eclipse. It does not matter what is the name of the project.
-
Right click on the name of the project and select ‘import’
-
From ‘General’ choose ‘Archive file’ and click next.
-
Click ‘Browse’ to select the a1.jar file that you have already download.
-
Click ‘Finish’.
If all the steps were done correctly you should see ‘Assignment1’ under ‘src’ and Junit5 under
the project. In case ‘Assignment1’ was not under ‘src’, drag and drop it to the ‘src’ folder.
This instruction is based on Eclipse but I'm using VSCode, so far I've been able to run Java just fine by using the java extension.
I've tried some suggestion from https://stackoverflow.com/questions/50232557/visual-studio-code-java-extension-howto-add-jar-to-classpath but it just didn't work (basically no Assignment1 under src).
Is there any solution to this problem or should I just simply switch to Eclipse.
My Project folder structure
答案1
得分: 1
你的问题是,你添加到文件夹Referenced Libraries中的库没有显示在src文件夹下,你想找到解决办法。如果对你的问题有任何误解,请告诉我。
官方教程:添加一个JAR 和 库配置 解释了如何将一个JAR添加到你的当前项目中。这里是一个简单的示例:
一旦你将库添加到引用库中,你就可以在你的代码中使用它。VS Code 是一个轻量但功能强大的源代码编辑器,它依赖于扩展来开发项目,这就是VS Code中的Java扩展包的工作方式。没有必要和Eclipse一样。
编辑:
当涉及到获取JAR包的源代码时,该命令有效:
jar xf jar-file [archived-file(s)]
关于如何反编译JAR文件,你可以参考这个链接。
英文:
Your question is libraries you've added into the folder Referenced Libraries aren't displayed under the folder src and you want to find its solution. If there's any misunderstanding about your question, please let me know.
The official tutorial: Add a JAR and Library Configuration explain how to add a jar to your current project. Here's a simple demo:
Once you've add the library into the referenced libraries, you can use it in your code. VS Code is a lightweight but powerful source code editor and depends on extension to develop projects, and this is how Java Extension Pack in VS Code works. There's no need to be as the same as Eclipse.
Edit:
When it comes to get the source code of a JAR package, the command works:
jar xf jar-file [archived-file(s)]
About how to decompile jar File, you can refer to this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论