Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to add Jar file or any other file/directory to classpath #94

Closed
hemang-ajmera opened this issue Feb 5, 2019 · 26 comments
Closed

Comments

@hemang-ajmera
Copy link

The extension does not support addition external jar file to the classpath. The only way is to manually add it to .classpath file. Please refer to https://stackoverflow.com/questions/50232557/visual-studio-code-java-extension-howto-add-jar-to-classpath/54535301#54535301

@akaroml
Copy link
Member

akaroml commented Feb 15, 2019

@yaohaizh please help link this issue to vscode-java's new feature of adding Jar dependencies directly.

@martinkoch-geniebelt
Copy link

I'm somewhat of a noob to this, but it seems quite odd to me that this is so difficult. Stackoverflow suggests a solution, but that doesn't work for me. I've tried both absolute and relative referencing of the jar file, putting the .classpath file in various locations, but it seems that vscode ignores it entirely. Any suggestions will be appreciated :) (I'd prefer a solution that works with the vanilla javac, e.g. without having to install maven)

@akaroml
Copy link
Member

akaroml commented Oct 25, 2019

@Vigilans please take a look at this issue. Users are looking for a way of adding dependencies to their projects.

@nimr77
Copy link

nimr77 commented Oct 30, 2019

It's so easy, anyway:
0. Creat project with java ctrl+shift+p

  1. add the jar file to your .classpath
  2. add on the top of your project package [app]; the name of your package
  3. We are done, don't forget to refresh it.

@akaroml
Copy link
Member

akaroml commented Dec 3, 2019

We are in the process of adding a UI entry for this. @Vigilans is on this.

@jdneo
Copy link
Member

jdneo commented Jan 13, 2020

Start from Language Support for Java@0.55.0, we added a new setting java.project.referencedLibraries to config the project classpaths. Please see this link for usage guide.

Meanwhile, in order to improve the UX, we had this PR to let the users be able to config this setting from the Dependency Explorer, which will be available in the next version of Java Dependency Viewer:
demo

Close this issue for now, but please feel free to let us know if you have any thoughts on this.

Thanks.

@jdneo jdneo closed this as completed Jan 13, 2020
@husseinkohy
Copy link

Start from Language Support for Java@0.55.0, we added a new setting java.project.referencedLibraries to config the project classpaths. Please see this link for usage guide.

Meanwhile, in order to improve the UX, we had this PR to let the users be able to config this setting from the Dependency Explorer, which will be available in the next version of Java Dependency Viewer:
demo

Close this issue for now, but please feel free to let us know if you have any thoughts on this.

Thanks.

java.project.refe.. libs in mac os is not working. it is not a multiroot project, etc all java dependencies installed. thanks

@jdneo
Copy link
Member

jdneo commented Mar 14, 2020

@husseinkohy What kind of project are you working on?

Let's say, Can you see files like .project, .classpath in your project's root path?

@husseinkohy
Copy link

thanks guys for responding. it is an https://ant.apache.org/ivy/ivyde/ project. yes .classpath and .projects are there, what is not resolving in .classpath is ref's like this.

<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=....

i could add the jar's individually as <classpathentry kind="lib" path="absolute path to a jar"....> but that would not be the ideal way.
there is a plugin (https://archive.codeplex.com/?p=ivyvisual) but it is not in .vscode market place

@jdneo
Copy link
Member

jdneo commented Mar 15, 2020

I see. Just as you said, some of the classpathentries needs to be resolved by the specific IvyDE plugin, while this plugin is not support VS Code right now. So I'm afraid you have to use the workaround you have mentioned right now.

@mp768
Copy link

mp768 commented Mar 22, 2020

can you give a tutorial on how to set up through video, because I'm not entirely understanding it.

@jdneo
Copy link
Member

jdneo commented Mar 23, 2020

@mp768 What kind of project are you using?

  • Maven/Gradle
  • Eclipse (no pom.xml or build.gradle, but you can see .classpath/.project on the project root path)
  • Standalone (no pom.xml, build.gradle, .classpath, .project)

@brunoborges
Copy link
Member

Confirmed: not working on macOS. Tried with a "naked" project.

@micheledellaciana1
Copy link

Hi, I'm trying too to use referencedLibraries to include libraries, but it doesn't work... no effect at all and I work on windows 10.

I see also that using java dependency you can add external lib with the interface, (using the add button in the corner). I haven't the button, and folders are labeled with (Read-only).

By now the only way I can add external lib is to typing directly the classpath file.

Cattura

WIth eclipse, no problem to add libs in the same project.

Thk in advice for help

@jdneo
Copy link
Member

jdneo commented Apr 8, 2020

@micheledellaciana1 I guess your project is an Eclipse project, which is so far not supported to manage libs in the dependency viewer.

Here, what we supported is the non-project files/folders, which means, there is no .classpath or .project in your project base path.

@micheledellaciana1
Copy link

ahhh Now I get it! Everything works fine! Many thanks! :))

@labibhussain
Copy link

Is a .classpath file absolutely necessary?

I've been having issues with incorporating .jar files from an external library into my project on vscode. The project was standalone and was not made through a "create Java app" function, so my directory does not contain an .classpath files. However, I was able to add the necessary .jar files to a lib file as well as have the Java Dependency View recognize the two .jar files I wanted to add.

However, when I try to compile a file that imports one of these files, I keep getting compiler errors saying that the package does not exist. Any idea as to what the issue could be? Here are a few pictures of the jar files located in my directory:
Screen Shot 2020-04-19 at 12 20 30 AM
Screen Shot 2020-04-19 at 12 20 14 AM

@gerrywp
Copy link

gerrywp commented Nov 27, 2020

Start from Language Support for Java@0.55.0, we added a new setting java.project.referencedLibraries to config the project classpaths. Please see this link for usage guide.

Meanwhile, in order to improve the UX, we had this PR to let the users be able to config this setting from the Dependency Explorer, which will be available in the next version of Java Dependency Viewer:
demo

Close this issue for now, but please feel free to let us know if you have any thoughts on this.

Thanks.

你好,请问怎么引用本地的.class字节码文件夹呢?这里只能添加.jar包,并不能添加一个包含.class文件的包的目录噢!

@jdneo
Copy link
Member

jdneo commented Nov 27, 2020

@gerrywp It's only supporting jar file right now, please feel free to create new feature requests here if you want more support

@HuskyNator
Copy link

What about adding it to projects that use maven? Those don't show a "Reference Libraries" section 😞

@jdneo
Copy link
Member

jdneo commented Feb 16, 2021

@HuskyNator we recommend to directly update the pom file, since that is the source of the truth of what the project build process. (otherwise, the build result in VS Code might be different from that in CI/CD).

BTW, we do have the same request here. Please feel free to upvote it. If more and more people are requesting for it. We will consider to support this feature.

@kartercs
Copy link

kartercs commented Jul 6, 2022

Hello,

i'm not sure i'm in the right place but i have been searching for days how to handle the eclipse project USER_LIBRARYS i have.

My project is a Eclipse project with the .classpath and .project visible in vscode, my coworkers all use Eclipse and they have those two files in version control, so i can't delete or modify it (at least i can't delete entry in the .classpath).

my classpath file looks like this :

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry excluding=".classpath|.gitattributes|.gitignore|.project|.settings/|branch.properties|build.xml|common-lib.xml/" kind="src" path=""/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JAVATOOLS18"/>
	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/COMMON_MASTER"/>
	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/COMMON_DMPV2"/>
	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/COMMON_DMP"/>
	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JEEBOP_MSSPRO"/>
</classpath>

and the Java project window show me all the entry like this :

image

The JRE.CONTAINER is found and all the libs are ok for this one, but all the others are totaly empty ( should have about 80 libs in those ).

As the project is "managed" the use of "java.project.referencedLibraries" doesn't work and i can't add the jar manually either since everything is readOnly in the "Configure Classpath"

I'm sorry for digging this up but i'm really lost on this..

Is it just not supported and i have to use eclipse, do i need to try to find a way to remove the .classpath and .project of the version control so i can use "java.project.referencedLibraries" or is there a way i make it work in vscode? Or maybe a way to ignore those .classpath and .project so that it is unmanaged and i import all the libs in settings.json ?

@jdneo
Copy link
Member

jdneo commented Jul 7, 2022

@kartercs AFAIK, USER_LIBRARY is not supported.

Or maybe a way to ignore those .classpath and .project so that it is unmanaged and i import all the libs in settings.json?

Should work in this way. If it does not, please let us know.

@kartercs
Copy link

kartercs commented Jul 7, 2022

Thanks for your answer @jdneo !

I finnaly made it work by changing names of .classpath and .project files, so that it's unmanaged, but then vscode told me it was not a java project anymore.
I had to add this to settings.json

    "java.project.sourcePaths": ["."],

Then i just imported all the libraries in the settings.json and it all worked !

The only "problem" i have between this and eclipse is that the order in which you declare your imports doesn't seem to have an impact on which lib is used, in the .classpath the first libs are always used over the other one if there is a conflct.
Here i tried to put the one i want to be the default in first or in last but it still use the other one.
I know we shouldn't have conflict but yeah...
Do you think there is a way to do this? Or maybe i need to make a feature-request?

Thanks again for all of this, using eclipse was a nightmare for me !

@jdneo
Copy link
Member

jdneo commented Jul 7, 2022

@kartercs So far, the unmanaged folder does not have the concept of import order for those referenced libraries. Please file a feature request for that :)

@kartercs
Copy link

kartercs commented Jul 7, 2022

@jdneo Thank you so much for your fast reponses !
I just did the feature request if someone need to find it's there #1023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests