Import project (jar) into Eclipse

66,796

Solution 1

I have managed it this way: New Java Project -> Java settings -> Source -> Link source (Source folder). There I added my decompiled jar and it was imported correctly :)

Solution 2

You can also create a new Java Project and then do File -> Import -> General -> Archive File. This will save you a step of unzipping your jar and adding as a linked source folder.

Solution 3

You cannot import a jar that way, unless it has the source code packed in the jar. If you really need the source code, you'll have to find an archive somewhere. But of course, not everyone is willing to share his source...

Solution 4

I tried the below and it worked.

  1. Create a New Java Project
  2. Goto File > Import > General > Archive File
  3. Select the required Archive file(.jar in this case) from your local system.
  4. Select the project you created in Step 1 and click Ok

This will save you a step of unzipping your jar but if there are .class files, eclipse won't convert them to .java files. This has to be done seperately.

Share:
66,796
Jane Doe
Author by

Jane Doe

Updated on July 13, 2021

Comments

  • Jane Doe
    Jane Doe almost 3 years

    I got a .jar file which I need to import into Eclipse. However, I don't want to have the jar as a referenced library. I need the .jar to be included like a "normal" project, with packages(!) and .java files.

    I tried to do the following: New Java project -> Import -> General -> Archive File. In this case, when I place this jar also as a referenced library, it is imported but with .class files.

    New Java Project -> Import -> General -> File System. Imports the .java files, but the packages are lost and are normal folders. Also, the files are somehow strange, because the "j" in the icon looks differently, and errors are not noticed (no underlining)

    Importing "Existing Projects into Workspace" doesn't work at all, it says that there is no project. I also tried to import the jar as a zip after extracting it, this gives me the -java files, but it destroys the packages.

    Does anyone know how to import this correctly?

  • Jane Doe
    Jane Doe about 11 years
    I managed it (see answer below) - however I cannot accept my own answer right now. I know that not everyone is willing to share his code, but this is a company project.
  • user1666456
    user1666456 over 5 years
    This works if you select the src folder as a target and not the project folder.
  • user1666456
    user1666456 over 5 years
    This works if you select the src folder as a target and not the project folder.