I am trying to decompile a java project(.jar) file and I am able to get .java files from it. Now how can I compile it back? I am able to add the .java files to Netbeans just as a single file.But how can I add it as a project add compile it? The project is a JavaFX project. So please help me on this.
There are many ways to achieve this, but I don't think you will be able to import the project inside the jar just out of the box ( in this case, out-of-the-jar ) like that.
We can use the most basic technique ( a bit dirty I admit ) but it works.
- Extract the contents of the jar in a directory and decompile it like you done it before
- Next, make an empty project inside netbeans ( with no src directory or anything )
- Copy the contents of your decompiled project into this netbeans folder. You should now see a skeleton structure of some files. Note The poject is inisde netbeans but it is not a java project yet.
- Edit the classpath of the netbeans project and add java library to make it into a Java netbeans project.
The other technique that I use sometimes is that I make all the project files required by the IDE (Eclipse in my case) manually and then tell eclipse to import the project. When eclipse finds all the required files ( .project, .classpath and all ), it imports into the IDE just fine
- Create a JavaFX project in your IDE.
- Decompile the jar to get the java files. The files will be places in different folders and sub folders based on the packaging.
- Put the folders as packages in the project created in step 1 above.
- Clean and compile the project in your IDE.
P.S: Make sure you respect the license agreements if you are planning the use the decompiled and recompiled classes in your project.
来源:https://stackoverflow.com/questions/23670227/decompile-a-java-project-and-compile