redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 438 forks source link

Can someone tell me how to import a jar package in VScode? #346

Closed xufangda closed 6 years ago

xufangda commented 6 years ago

I'm sorry to ask this silly question.

But I've been searching everywhere to learn how to import a jar package in vscode.

Suppose the jar file is in C:/java/lib/package.jar directory, how can I import it in vscode??

Environment
gorkem commented 6 years ago

Are you using the .jar as a library? Or import contents of the jar to modify them?

gorkem commented 6 years ago

closing since no activity

mohamed-ismail-1780 commented 6 years ago

i have the same problem, how to add the external jars to VS code?

fbricon commented 6 years ago

@ismailashik what sort of project are you working with? Maven, Gradle, Eclipse?

mohamed-ismail-1780 commented 6 years ago

eclipse java project

fbricon commented 6 years ago

So if you added a jar dependency in Eclipse, reopening the same project in vscode should work, if it's a simple Java project. If it doesn't, please provide a sample project reproducing the issue

mohamed-ismail-1780 commented 6 years ago

here is the sample eclipse project. i could not import this eclipse project with VS code. I have to use the folder source test_vs_code.zip

fbricon commented 6 years ago

Works for me (after pointing to a json.jar on my machine). It even works in Atom.

Can you try opening this one (the jar is included in the project directory, so it's more portable)? test_vs_code2.zip

mohamed-ismail-1780 commented 6 years ago

how did you point the json.jar in vscode?

fbricon commented 6 years ago

check .classpath

mohamed-ismail-1780 commented 6 years ago

this is what i get when i open the folder that you have sent.

image

fbricon commented 6 years ago

this is NOT vscode-java's output!

Please disable/uninstall other Java Language support extensions, make sure you only have the one from Red Hat.

fbricon commented 6 years ago

To launch and debug your Java programs, it's recommended you install Java Debug Extension for Visual Studio Code.

mohamed-ismail-1780 commented 6 years ago

Now i get this error.

[Error - 3:09:45 AM] Nov 24, 2017 3:09:42 AM Invalid project description. [Error - 3:09:45 AM] Nov 24, 2017 3:09:42 AM An internal error occurred during: "Initialize Workspace". org.eclipse.core.internal.resources.ResourceException: Invalid project description. java.lang.RuntimeException: org.eclipse.core.internal.resources.ResourceException: Invalid project description. at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter.importDir(EclipseProjectImporter.java:96) at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter.lambda$0(EclipseProjectImporter.java:63) at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter$$Lambda$29/568268184.accept(Unknown Source) at java.util.ArrayList.forEach(ArrayList.java:1249) at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1080) at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter.importToWorkspace(EclipseProjectImporter.java:63) at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.importProjects(ProjectsManager.java:100) at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.access$1(ProjectsManager.java:94) at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager$1.run(ProjectsManager.java:88) at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:724) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5660) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5617) at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.initializeProjects(ProjectsManager.java:82) at org.eclipse.jdt.ls.core.internal.handlers.InitHandler$1.runInWorkspace(InitHandler.java:157) at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56) Caused by: org.eclipse.core.internal.resources.ResourceException: Invalid project description. at org.eclipse.core.internal.resources.Project.checkDescription(Project.java:169) at org.eclipse.core.internal.resources.Project.assertCreateRequirements(Project.java:53) at org.eclipse.core.internal.resources.Project.create(Project.java:263) at org.eclipse.core.internal.resources.Project.create(Project.java:247) at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter.importDir(EclipseProjectImporter.java:92) ... 18 more

mohamed-ismail-1780 commented 6 years ago

that loading stuck on 28%

image

fbricon commented 6 years ago

Try cleaning the workspace directory

mohamed-ismail-1780 commented 6 years ago

thanks it works perfectly

nitink133 commented 6 years ago

How can I add .jar file using maven dependencies. Well,I am trying to import itext library,as we add dependencies in eclipse I just add them in pom.xml but here is the problem raise and I am getting error that class Document not found and so on.

DhruboB commented 6 years ago

I solved this problem by doing following..

  1. removing all java extension (including RED HAT one)
  2. including all maven id for those jars in pom.xml
clankill3r commented 5 years ago

Why is it so shit to add a .jar in every editor out there. Should have been a simple text file with a absolute path on each line.

OldPlanesRock commented 5 years ago

Hopefully you have installed the Java Dependencies extension. There is a .classpath file in the root of you project folder. Open it with vscode. It will look something like:

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> <classpathentry kind="lib" path="D:\opencv_2413\opencv\build\java\opencv-2413.jar"/> `

add this classpathentry: <classpathentry kind="lib" path="path to your opencv jar file, or any library\opencv-2413.jar"/>

Nice reference here: https://dzone.com/articles/visual-studio-code-for-java-the-ultimate-guide-201

enfarious commented 5 years ago

It'd be so nice if you could just drop the file in your working folder and: right click > add lib to classpath ...

akaroml commented 4 years ago

It'd be so nice if you could just drop the file in your working folder and: right click > add lib to classpath ...

I think @jdneo @testforstephen are working on something related to this idea. Would you guys share more thoughts?

namnguyen191 commented 4 years ago

Are you using the .jar as a library? Or import contents of the jar to modify them?

Hi,

How would you import the contents of the jar to modify them? I was able to import the jar as a dependency but the source codes aren't showing.

jdneo commented 4 years ago

import the contents of the jar to modify them

Do you mean you want to modify the source code of the imported jar?

Court247 commented 2 years ago

Are you using the .jar as a library? Or import contents of the jar to modify them?

could you just answer the question anyway?