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.
Related
I have a running Java web application from a previous employee which I am trying to fix. I literally just need to fix one line in .java file. However, I have problems rebuilding it and running the new version with Tomcat. When I try to rebuild the files, it doesn't actually change any of the source files.
I'm at a bit of a loss when it comes to going about recompiling/rebuilding the .java files. Do I need any additional tools for it?
You can import the project in to an IDE and add ant task then run build.xml to build your project. After that you can change your java class and build the project then get the class file and replace it into old project
Recently I worked on a project on a mac, using eclipse. When I was done with the project I copied certain .java files and their corresponding .class files onto a USB drive and brought it to my personal computer. When I try to use the import feature on eclipse and import everything, my main method is not recognized by eclipse. It will work if I create a new eclipse "class" by the name I have in the program and copy paste the code. I have many classes so I can not do this for each one. Is there any way for me to change all .java/.class files into files that will be read by the system?
Thanks
An eclipse project contains a lot of meta information. Just open the project directory in a file browser, and have a closer look. There are files like .classpath for example.
When you just copy your source code, you leave all the meta information behind!
You should either copy the complete project directory, or simply use the export task to create a ZIP file of your project. (to later import that in other systems).
There is one other way you can do this. Just create a new project with the SAME EXACT PROJECT NAME that you did at school or wherever. After you create your project, go to your file explorer and navigate to the following place:
<"Directory to work-space">/<"Project Name">/src/
For ex: in Windows, it is Generally:
C:/Users/your_name/workspace/projectName/src
In here, copy all your ".java" files.
Now go to eclipse, right click on your project and hit refresh. You will find all your .java files there. Right-click on your project and hit "Run"->"Run as a Java Project". It should run! hope this helps.
PS: You do not need your class if you are executing it in Eclipse. Eclipse will create its own class files.
How can I get the full java code of a netbeans project? I have created a project for a contest, but need to submit the whole code. In Netbeans alot of the libraries and classes code is hidden. I need to submit all this. Even if a plugin needs to be installed.
Thank You :)
Assuming you have a NetBeans Project named HelloWorld in your system,let's assume that the default directory of storage of NetBeans Projects is in
C:\Users\USERNAME\Documents\NetBeansProjects\HelloWorld // On Windows OS
/home/NetBeansProjects/HelloWorld // On *nix(Linux,Unix) based OS
If it is different from the above,then please switch to the default directory of the Netbeans Projects.
Select your project folder from that,HelloWorld here.
It'll have several directories(folders) inside.
Switch over to src folder. All the .java files are placed in that directory. Those are the source code in Java. You can open and check and verify those files using any text-editor like Notepad,Gedit,etc.
NOTE :- DON'T DELETE ANY OTHER FOLDER/FILES unnecessarily,else,your NetBeans project won't be recognised/won't run properly.
I have a java project that I created in the NetBeans IDE version 8.0.1. The project contains a gui which I created with the NetBeans Gui builder, two external API's, and of course some of my personal code. I would like to make this project available to the public, but I don't want someone to be able to just take my project and upload it into an IDE and see all of my work. How do I need to go about making my project codew private and/or inaccessible. All the user should be able to do is run the jar file and use all the functionality of the program. Thanks for the help!
By default JAR files are build without sources if you use NetBeans (with its Ant-based build system), Maven or Gradle. It will only contain *.class files and resources (text, XML, images and other files).
Of course it is possible to decompile *.class files from your JAR. If you want to go an extra step you can obfuscate generate code to make it harder to understand what's going on there.
I have a program I am making for a friend. It contains one class, references two libraries (sqlite4java and poi by Apache), and sqlite4java contains many native libraries (.so, .dll, .jnilib) that are within my lib folder. The program also reads and writes from a swimTeam.db file.
My question is how do I package this all into one program that can be run cross-platform? I have tried exporting the project as a runnable jar, but when I ran it it couldn't access the native libraries because they weren't exported. Any idea how to do this?
First thing is create a java project remove all the java files and copy all the Jar file you need to import into that project.
now add the the created project to your working project as "project references" (right click on the project and click on properties)
now add all the Jars in the Java buildpath->libraries
now export your project as JAR. open it and make sure that all the JARs u need are in it.