I made a big error and I need your help:
I work on a project for the school with java and I made a big error!
I sent to me only the *.class files and deleted the other files(I work in my school with VM).. Is there a way to compile these .class files to .java files?
Thanks
You need to use decompiler for that not the compiler.
First decompile using decompiler and then do some changes what ever you needed and then again compile it.Than your problem will solve
SEE HERE
Try the Java Decompiler. It should be able to reverse your .class files.
You can also try Show my code if you don't mind submitting your .class files online.
You should be aware that different decompilers may give different results, so trying different ones may be helpful. See Choose and test java decompiler
The utility you need is called java decompiler. There are several available.
Try JAD from command line. You can also install plugin for eclipse.
And BTW if you are on windows is it possible that your source files are in recycle bin? Or if you are using eclipse try to check the eclipse local history (right click on your project and choose "Restore from local history")
You need to decompile your class file. But, after decompile you also need some necessary changes to get your original java file.
Try this.
I preper using JD-GUI. You can download from link http://java.decompiler.free.fr/?q=jdgui
Dont Worry download DJ Java Decompiler 3.7 download only this version.
Related
I'm new to java and learned that when creating a .java file usually there's a .class file generated automatically, which happened to the previous java files I created.
However, I forgot since when VSCode stops doing this when I create new java file.
Another problem is, when creating a new java file, the shortcut to type "main" and press enter doesn't generate
public static void main(String[] args) {
}
anymore. I have to literally type out the whole thing, otherwise I have to close this new file, open again, wait a few seconds to half a min or so for the shortcut to work.
Any reason why?
The .class file is generated by compiling the .java file. The following settings in settings.json control the generation of .class files in the bin directory.
"java.project.outputPath": "bin",
In addition, you need to download the Extension Pack for Java, read the official document for more help.
Also check the following settings to control the location of code snippet suggestions.
"editor.snippetSuggestions": "inline",
Sounds like you've used some sort of IDE before, maybe IntelliJ or Eclipse.
The .class files
The .class files are compiled Java source files, containing JVM bytecode. These are generated when you build your Java program, either via a build tool (Maven, Gradle, Ant, etc..) or by compiling the sources. Now, if you use an IDE in most cases the IDE will take care of building your project. If you use the stock VSCode without any Java related plugins, VSCode doesn't know how to build a Java project out of the box. I believe you can define a build task, and run that, but it doesn't support it out-of-the-box, without any plugins. So you should look around in the VSCode plugin marketplace what Java-experience-enhancing plugins you can add.
Code snippets and shortcuts
Not sure why you have to reopen files for shortcuts to work. That being said, you're looking for code snippets, or IIRC IntelliJ calls these live-templates. These are, well, templates for code generation, which you can invoke in your editor. IIRC VSCode doesn't have any Java related code snippets, you have to add them yourself or install a plugin that provides these. In IntelliJ, you have built in templates or snippets for stuff like the main function, for-each blocks, etc.. but again, IntelliJ is a JVM-focused IDE, a very good one too. VSCode is a really good tool, but you may have to install some plugins and add stuff in order to have the cosy IDE-like experience.
I have a Java program someone else wrote and I'd like to "decompile it" into its sources so I can modify its code. I have tried to do it and have decompiled a jar but when I try to recompile the Java files into jar's I get a bunch of dependency issues because I do not have the source files for the dependencies(although I have some of them but it doesn't seem to help).
Is there any program where I can drag and drop the Java exe or install directory and it will, I guess, decompile everything so I can modify some of its sources and recompile it? I've done this before but can't recall what app I used. The original program is written in eclipse.
The code you are attempting to re-compile has dependencies on classes you don't have.
Rather than re-compiling the whole jar, you only need to re-compile the classes you changed.
If these classes depend on classes you don't have you can create stubs for those classes which will allow you to compile the classes you changed.
I would like to suggest to used jd-gui.exe. It can easy to decompile the jar file and content will see clearly ...
I have one War files (a Java application) consist of 64 class file along with image/CSS/JS files. I have lost the source of this war file. Now I want to do some changes in code. I am looking for some expert advice from community on following questions.
Is there best way to convert .class files to .java file without losing any section of code?
What are the tools if any for this task?
What are challenges/drawbacks of converting .class files to .java files to recreate war file?
If you do not want to spend horrible times in understanding decompiled bytecode, please start using a version control system and a remote repository for any project of more than two classes.
In particular, you can use Git with GitHub, open source are hosted for free while if you want to protect your code you can get a commercial subscription which is cheap anyway.
For this time, help yourself with a java decompiler such as JD:
Use a java decompiler to decompile the bytecode.
Create a git repository out of the decompiled java classes
Constantly synchronize it with the remote repository
Conversion to Java Bytecode is almost completely reversible. As #StephenC said, In the regenerated sources, you will lose comments, names of local variables etc. It might not compile right away but you should be able to get it to compile again, with a little modification.
You need a Java Decompiler to do that. Try JD-GUI or DJ Java Decompiler
In case you obfuscated your sources, the sources you recover will not be harder to understand and reverse engineer. Otherwise, with just a little tinkering, you should be able to get back your sources.
first i'd like to point out that im fairly new to netbeans and java, couldnt exactly find what i need on the web.
I downloaded a software's source files and was modifying it on netbeans. naturally when building the project, netbeans creates in (for example) documents/project_folder/dist/ a lib folder and the finished JAR file that i can use.
if i delete by mistake the source files, and would like to apply all the changes i previously made to fresh source files using the JAR and lib folder i still have, is it possible and how?
First of all it is not possible to get a source again from jar file in lib folder. Jar file is executable file which will just contain class files. You can use java decompilers to get source again.
NB do not has a version control nor auto save by default. You may have a look on git in NB7.
When you restore from Jar with decompiler there is a big chance to get the source back, even more if you know what your code is all about.
You can get the source back by using some decompiler. There are many decompilers available like DJ Decomipler. My favourite is Jd Java Decompiler. Its very small in size and does its job pretty well
I'm rather an Eclipse user but I guess both Eclipse and Netbeans are similar to a certain extent. Unless the jar has been created including the source, you won't have other choices that decompile the class files.
When needed, I usually go with JD-GUI which does a pretty good job decompiling jars.
It is not possible to retrieve exact source code from a compiled byte code. But there is a possibility to recover your code to some extent
JD is a good Java decompiler.
http://java.decompiler.free.fr/?q=jdgui
I think JD is a super hero in cases that the original source code is lost.
Keep your source code on any SCM. Use remote SCM not to loose your code. See: google code, github, launchpad etc.
I recently lost my netbeans project folder of the project that I was working on at the time. However somewhere on a server here at the company that I work at, I deployed it. So that means that I (hopefully) can still get hold of the .war file.
Is it possible to then 'unpack' this .war and get my .java source files back that I was working on at the time?
Thanks in advance!
If the .java sources aren't in the WAR (and they should not be), you'll have to take the additional step of decompiling them using a tool like JAD.
This is a good time to set up a version control system, like Subversion or Git or Mercurial, so this never happens to you again. Get into the habit of using source code management, even if you're the sole developer working on the project.
Short answer: No.
Slightly longer answer: Look for Java decompilers, but they won't give you your Netbeans project folder.
You only get *.class files from your war (rename war to zip and use a decompression tool).
Then you could decompile them.
See this related question for some suggestions.
Suppose if you had exported the source files while creating the war, you can get it. Else, JAD is your only hope that too cannot fully rely on it.
It is possible to unzip the war file where you will get only class files and other property files. Then use Java decompiler to see source code and it works really well (not recommended).
Also you can change the property files without JD and all you need to do just change the property files and zip to war file again.It will work.
But I would recommend you to maintain source code in SVN or TFS or multiple copies with version numbers in local system at any point of time.
In Eclipse, you can Import your War, it will create a new Project and set the resources in the project structure. IF your war holds the source java files, the project will cointain your sources. IF not, the packages will be empty and you will have to manually decompile your classes from bytecode to java files, using jad or another decompiler.