Vscode-java: Hi. Can someone tell me how to import a library in VScode?

Created on 5 Dec 2017  路  10Comments  路  Source: redhat-developer/vscode-java

I just switched to VS Code from IntelliJ.

But I couldn't figure out how to import a jar in VSCode? I'm using it as a library.

I have some libraries, for example, Junit.

Operating System: Mac Sierra
JDK version: 1.8.0_131

Thank you.

duplicate question

Most helpful comment

Hi fbricon,

Thanks for the quick reply.
I just tried to manually create .classpath file. It didn't work.
The link isn't answering my question.

So for example, I've just created a .java file in VSCode.
Now I want to import an external library. So I can have this line of code working: import org.junit.Test;

I kind of feel this is a silly question. But I just can't figure out how to make it work.

Thank you for your help. :)

All 10 comments

Duplicate of #346

Hi. I'm confused. So what I need is a .classpath. But it's not an Eclipse project.

Is there a way to generate .classpath file? or I have to manually create one?

Hi fbricon,

Thanks for the quick reply.
I just tried to manually create .classpath file. It didn't work.
The link isn't answering my question.

So for example, I've just created a .java file in VSCode.
Now I want to import an external library. So I can have this line of code working: import org.junit.Test;

I kind of feel this is a silly question. But I just can't figure out how to make it work.

Thank you for your help. :)

So if I understand this right, I need .project and .classpath to make it work.

yes, both are required. Please check https://github.com/redhat-developer/vscode-java/files/1500211/test_vs_code2.zip see how the jar needs to be referenced in .classpath.

Using a Maven or Gradle project can be very simple to get started, instead of aiming for the Eclipse route. And it'll make your project IDE agnostic.

Cool!! Thanks for the example code. It works. Basically, all I need is to start a project in Eclipse. I will try Maven tomorrow. It is so weird that VS Code supports Eclipse, Maven, and Gradle, but IntelliJ is not included.

I have one more question. The Junit still doesn't work in VS Code. Other libraries are fine.
I have Java Test Runner installed. But when I click Run Test, it shows this (below in the photo). But the same project works fine in Eclipse.

Do you have any idea how to fix it?

screen shot 2017-12-07 at 1 59 11 am

and how do you use the .jar in visual studio code ?

Is it still the same manual process now (to update .classpath file)?

Was this page helpful?
0 / 5 - 0 ratings