VSCode:如何将一个jar文件导入你的Java项目中?

huangapple go评论80阅读模式
英文:

VSCode: How to import a jar file into your java project?

问题

以下是翻译好的部分:

我对Java还不太了解,在我大学的课程中,我的教授给了我们以下的指示:

  1. 下载附加的 .jar 文件。

  2. 在 Eclipse 中创建一个 Java 项目。项目的名称不重要。

  3. 在项目名称上右键点击,然后选择 ‘导入’。

  4. 在 ‘常规’ 中选择 ‘存档文件’ 并点击下一步。

  5. 点击 ‘浏览’ 以选择之前已经下载好的 a1.jar 文件。

  6. 点击 ‘完成’。

如果所有步骤都正确执行,你应该在 ‘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:

  1. Download the attached .jar file.

  2. Create a java project in eclipse. It does not matter what is the name of the project.

  3. Right click on the name of the project and select ‘import’

  4. From ‘General’ choose ‘Archive file’ and click next.

  5. Click ‘Browse’ to select the a1.jar file that you have already download.

  6. 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添加到你的当前项目中。这里是一个简单的示例:

VSCode:如何将一个jar文件导入你的Java项目中?

一旦你将库添加到引用库中,你就可以在你的代码中使用它。VS Code 是一个轻量但功能强大的源代码编辑器,它依赖于扩展来开发项目,这就是VS Code中的Java扩展包的工作方式。没有必要和Eclipse一样。

编辑:

当涉及到获取JAR包的源代码时,该命令有效:

jar xf jar-file [archived-file(s)]

VSCode:如何将一个jar文件导入你的Java项目中?

关于如何反编译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:

VSCode:如何将一个jar文件导入你的Java项目中?

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)]

VSCode:如何将一个jar文件导入你的Java项目中?

About how to decompile jar File, you can refer to this.

huangapple
  • 本文由 发表于 2020年10月9日 10:37:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64273185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定