8

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?

1
  • 1
    Import the jar then attach the source? Commented Mar 13, 2013 at 8:27

5 Answers 5

9

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 :)

Sign up to request clarification or add additional context in comments.

Comments

7

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.

1 Comment

This works if you select the src folder as a target and not the project folder.
4

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...

1 Comment

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.
3

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.

1 Comment

This works if you select the src folder as a target and not the project folder.
2

Below helps in all recent eclipse.

Please try below eclipse plugin to import jar as project :

Step 1) Eclipse Help > Eclipse Marketplace
Step 2) Install the plugin "Import Jar As Project"
Step 3) Restart Eclipse
Step 4) File->Import->Other->Jar without source
Step 5) Select a jar/war file and click finish

New project will be created from the jar

https://marketplace.eclipse.org/content/import-jar-project

Thank You.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.