How to open jar file in Eclipse

I downloaded the jar demo file and would like to open it in eclipse. I did it

import-> Existing projects in workspace β†’ select archive file

However, eclipse returns "No projects to import."

Type command line

java -jar projectDemo.jar

This jar file just functions well. It seems to me that the jar file is on its own, but how can I open it in Eclipse and change this demo code? Thanks.

+4
source share
6 answers

Because the jar file β€œexecutes,” it contains compiled java files known as .class files. You cannot import it to eclipse and modify the code. You should ask the "demo" provider for the "source code". (or check the page where you got the demo for the source code)

If you do not want to decompile .class files and import them into Eclipse. This may not be the case for beginners.

+7
source

use java decompiler. http://jd.benow.ca/ . you can open jar files.

Thanks, Manirathinam.

+3
source

The project is not exactly the same as the jar executable.

For starters, a project usually contains source code, while a jar executable usually does not work. Again, generally speaking, you need to export the Eclipse project to get a file suitable for import.

+2
source

Try JadClipse.It will open your entire .class file. Add a library to your project, and when you try to open any object declared in the lib file, it will open just like your .java file.

In eclipse-> help-> marketplace β†’ go to the popular tab. There you can find plugins for the same thing.

Update. For those who cannot find the plugin above, try downloading this: https://github.com/java-decompiler/jd-eclipse/releases/download/v1.0.0/jd-eclipse-site-1.0.0-RC2. zip

Then import it into Eclipse.

If you have problems importing over the plug-in, see How to Install the Eclipse Plugin from .zip

+2
source

First, you need to know what a jar file is.

From Oracle

JAR (Java Archive) is a platform-independent file format that aggregates many files into one. Several Java applets and their required components (files, images and sounds) can be bundled in a JAR file and then downloaded to the browser in one HTTP, significantly improving download speed. The JAR format also supports compression, which reduces file size, further improving download times.

As you can see,

  • This has nothing to do with the Eclipse project. An Eclipse project can be a Java project, a C ++ project, etc. This is just a self-preserving project that can be recognized and used as an Eclipse device.
  • .Class files are usually the main part of the jar file. It is not possible to view the source code (.java file) unless you decompile the executable file (.class file) using some tools. Take Eclipse, for example, you can choose the Eclipse Class Decompiler plugin as a tool.
+1
source

The jar file is just an executable Java program. If you want to change the code, you need to open the .java files.

-2
source

All Articles