Skip to content

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

Closed

Description

@hemang-ajmera

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

Activity

  1. akaroml commented on Feb 15, 2019

    @akaroml
    Member

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

  2. martinkoch-geniebelt commented on Aug 15, 2019

    @martinkoch-geniebelt

    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)

  3. akaroml commented on Oct 25, 2019

    @akaroml
    Member

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

  4. nimr77 commented on Oct 30, 2019

    @nimr77

    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.
  5. akaroml commented on Dec 3, 2019

    @akaroml
    Member

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

  6. jdneo commented on Jan 13, 2020

    @jdneo
    Member

    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.

  7. husseinkohy commented on Mar 13, 2020

    @husseinkohy

    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

  8. jdneo commented on Mar 14, 2020

    @jdneo
    Member

    vaanalyst (@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?

  9. husseinkohy commented on Mar 14, 2020

    @husseinkohy

    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

  10. jdneo commented on Mar 15, 2020

    @jdneo
    Member

    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.

  11. mp768 commented on Mar 22, 2020

    @mp768

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

  12. jdneo commented on Mar 23, 2020

    @jdneo
    Member

    Michael (@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)
  13. brunoborges commented on Mar 31, 2020

    @brunoborges
    Member

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

  14. micheledellaciana1 commented on Apr 7, 2020

    @micheledellaciana1

    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

  15. jdneo commented on Apr 8, 2020

    @jdneo
    Member

    Michele Della Ciana (@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.

  16. micheledellaciana1 commented on Apr 9, 2020

    @micheledellaciana1

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

  17. labibhussain commented on Apr 19, 2020

    @labibhussain

    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

  18. gerrywp commented on Nov 27, 2020

    @gerrywp

    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文件的包的目录噢!

  19. jdneo commented on Nov 27, 2020

    @jdneo
    Member

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

  20. HuskyNator commented on Feb 15, 2021

    @HuskyNator

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

  21. jdneo commented on Feb 16, 2021

    @jdneo
    Member

    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.

  22. kartercs commented on Jul 6, 2022

    @kartercs

    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 ?

  23. jdneo commented on Jul 7, 2022

    @jdneo
    Member

    karter (@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.

  24. kartercs commented on Jul 7, 2022

    @kartercs

    Thanks for your answer Sheng Chen (@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 !

  25. jdneo commented on Jul 7, 2022

    @jdneo
    Member

    karter (@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 :)

  26. kartercs commented on Jul 7, 2022

    @kartercs

    Sheng Chen (@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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions