1

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

rioV8
  • 24,506
  • 3
  • 32
  • 49
Nam
  • 554
  • 4
  • 11

1 Answers1

1

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:

enter image description here

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

enter image description here

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

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • Thank you for the reply. And yes I've tried the above method but it just didn't work. I need the source codes of the imported library to be display inside the project cause I'm tasked to modified this source codes. – Nam Oct 09 '20 at 13:50
  • @Nam Nguyen. Got it! You want to extract the contents of a JAR File. I'll edit my answer and please have a look at it. – Molly Wang-MSFT Oct 12 '20 at 01:32
  • Thank you! This is exactly what I was looking for. I actually did not know the .jar is just a regular compress file. – Nam Oct 13 '20 at 02:18
  • If my reply helps you, it's appreciate that you mark it as the answer, which will let more people see it. – Molly Wang-MSFT Oct 13 '20 at 05:27