Eclipse how to see the Java file instead of class file - java

I want to see the java file when i click the respective object or it's method. I knew that java files are compiled and it will be in the .class format. Is it anyway to see as a java file in eclipse by using plugins or Anyother tool is there to achieve this? So we can avoid to see the implementation of the object and it's method in the java portal's..

If you have the source available then use Attach Source feature. If not then any decompiler eclipse plugin is fine. My preference is JD-Eclipse.

If you have the source code, you can attach it so that it gets opened automatically. This is explained in Is there an easy way to attach source in Eclipse?
If you don't have access to the source, you can integrate a Java decompiler into Eclipse: Java Decompiler

If you have the source of the library (jar) you can add it (in the properties) of the jar, otherwise you can use "decompiler" plugin: http://java.decompiler.free.fr/

Related

Can you get a .java file from a .class file in Java

Was given a couple of .class files but the .java files weren't sent with and I was hoping to find a way to get the .java files using the .class files. Thanks
You can use a decompiler to do so. One of the most major ones is JD-GUI.
JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type “enum”, are supported. JD-GUI and JD-Eclipse include JD-Core library.
EDIT (2018-02-23): It seems that JD-GUI is incapable of decompiling bytecode compatible with Java 8+ JREs. This, obviously, changes the utility of my answer.
EDIT (2018-05-24): For replacing JD-GUI, I would recommend Luyten, which can be found here. It's very similar to JD-GUI, but supports Java 8 byte code, itself being based on Procyon.
You can use any of the java decompiler utility for this. There are a couple of few good utilities available over the internet, e.g., JD decompiler, you can also look for the eclipse plugin as well for the same.
To view java content from .class files many decompilers are available.
I'm using JD compiler which is very good.
http://jd.benow.ca/
If you want it for edit/ update puropse, one way is copy + paste from decompilers. Other solutions i'm not aware of.
You can use Jadclipse which is basically a Java Decompiler. It can be used with eclipse integration..
You can use decompiler to get .java files from a jar file or a .class file

Can we run decompiled java (jar to java)

I have decompiled a jar file. Can we run this file using eclipse or some other IDE. Or any way to do this. Thanks in Advance.
It depends on a number of things, such as:
whether the original JAR was runnable,
whether the decompiler produced compilable Java code,
whether the decompiler produced correct Java code, and
whether you have all of the dependencies for the decompiled code.
Note that decompilers tend to have difficulty with code that has been obfuscated, and code that uses the latest Java language features.
It depends on the decompiler used: some do produce compileable code, some don't. If your decompiler's output can be recompiled you could include it in an eclipse-project and run the main-class (if there is any).
Make sure to have all other dependencies of the jar-file in the build-path.
Yes you can If it contains main method in any of it's classes.
Yes you can run the decompiled jar file. Right click on the class which contains main method and select Run as Java application. If required, adjust the classpath (You cand do this in eclipse using java build path and debug settings)

Understanding JAVA code in external JAR libraries

I've been provided some external JAR libraries for a project I'm doing. I can access the compiled code but I can't really understand it as its not in the form I'm used to seeing. Any tips on how to 'de-code' and understand what's going on?
Thanks
Search the net for Java Decompilers (e.g. JAD). What you see in a jar is Java-Classes, i.e. the result of compiling .java files.
There are decomiplers you can use them to de-compile .class to .java. We are using JD Java decompiler.
NOTE: I think De-compilation (or) modifying de-compiled code is illegal in some countries. Be aware of it.
You could use a decompiler like JAD to decompile from .class file to .java files, but in my experience its use is quite limited
Try Java Decompiler (Yet another Fast Java decompiler) : http://java.decompiler.free.fr/ .
It can decompile your compiled library.
JAD is only supported up to 1.3.
There should be a documentation and/or source jar that you can attach to your IDE, which will allow you to access the documentation.
If not, you have to decompile it.
Keep in mind that it might be ok to treat this jar as a black box.

Is it possible to debug java source files in eclipse

Eclipse provides an opportunity to view java source code by using Source attachement in project's Java Build properties, but is it possible also to debug java source code?
I try to install breakpoint inside some java .class file and get :
Unable to install breakpoints in java source file due to missing line number attributes
You may have the compiler set to include debugging information in YOUR class files, but the class files in rt.jar weren't compiled that way. You need to either recompile all the source for the classes in rt.jar (not for the faint of heart), or download a debug build of the jdk.
Try to install a Java decompiler like Jad...

Viewing source code from a third-party jar in Eclipse

I am working on a Java project in Eclipse. In this I am using a third party JAR which I have put in on the classpath. Now I want to understand the code in the JAR file and want to see the actual code and navigate through the third party code just like my own code.
My question is this: Instead of me manually decompiling all of the class files in the JAR and putting them in the appropriate folder as per package declaration, is there some way in which Eclipse will decompile them for me, and put them in the appropriate folder? What should be the approach taken in such a scenario?
The decompiler I use is JAD. It has an eclipse plugin, Jadclipse.
You can download JAD from http://www.varaneckas.com/jad
You can get Jadclipse from http://sourceforge.net/projects/jadclipse/. Click on the download jar and then simply copy the jar into your Eclipse/plugins directory, and restart Eclipse. Set up the path to JAD from Preferences->Java->JADClipse. Then trying to view a class should give the decompiled code.
I have been using Java Decompiler for some time and have found it very useful, i don't know about eclipse but it seems to have a eclipse plugin: JD-Eclipse

Categories

Resources