简体   繁体   中英

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

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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