Is it possible to debug java source files in eclipse - java

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...

Related

How to change the CodeRunner .class file creation from same working directory of the java file in vs code?

I am currently using vs code to run my java files.
But when I use coderunner and run my java file it creates a .class file for every class in the same directory of my java file. Which gets messy how can I get rid of that?
I am ok with uninstalling the coderunner but in that case the java file errors doesn't show up properly and build fails.
Uninstall Code Runner and choose Java: Create New Project from Command Palette.
Create a no build tools project and coding in .java files which stored in folder src, then all the generated .class files will be stored in folder bin by default.
About the compilation errors, please post code snippets for further solution.
Install Test Runner for Java or Extension Pack for Java extension both by Microsoft. Better would be to go with an extension pack.

VS Code runs .java files without the producing .class files

I have some basic java knowledge and i decided to switch from Intellij to VS Code. I know how to compile and run a java file (which may use other imported .java files) from the terminal, but i want to run a java program using the run icon inside vs code.
I'm not a 100% sure, but i think that in order to run a java program inside vs code you need a extension. For this reason i downloaded the Java extension pack. Note that i already have installed the latest jdk on my computer.
After i installed the plugin, i could run the program using the "run without debugging"/clicking in the run icon. However, no .class files are produced. I control+h but there isnt any hidden folder that vs code may drop the .class files.
How does the program run in the first place?
How can i config vs code in order to compile the java files before running the one that has the main function?
Basically, when you run a java file normally, you compile it with javac and then run it with java (or something along those lines, there are many different variations of possible ways to do it). If you go ahead and try, it is possible to run java filename.java and skip the normal javac step. In the case of VSCode, it will differ based on what extensions you have, but some may run the code with a simple java filename.java and others may have different settings set. If you take a look at your extension preferences as well as your preferences for java by searching your settings, there may be an option, such as "Java Source Paths" enabled which changed where compiled files are saved by VSCode.
If your project is a folder containing Java source files. And no build tools(Maven/Gradle) are used.
If that is the case, you can trigger the command Java: Configure Classpath, then find the section output and then set a relative path to your workspace.
The output files are by default stored inside the workspace storage.
If after triggering the command, what you see is the native vs code setting page. Then try to search java.project.outputPath and then set a relative path to it.

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)

Eclipse how to see the Java file instead of class file

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/

How does one build the java JRE from source (src.zip in JDK)?

Surprisingly enough I couldn't find the answer to this question.
I am trying to rebuild the java JRE from source. I obtain the java JRE source by extracting the src.zip file in the JDK.
After making any changes I need to make to the JRE, how do I compile the new source back into .java files (after which I can compress it into the rt.jar file).
Thanks.
You have better chances using OpenJDK (the base of Oracle/ Sun's future JDKs).
http://openjdk.java.net/
But what do you want to change actually? Maybe there is a better way...
Some of the Java sources that make up
rt.jar are generated during the build
process, from scripts and other means.
Some of the properties files are also
generated this way, and some of the
properties files are turned into Java
source that also contributes to
rt.jar. So without doing a complete
build first and populating the
'gensrc' directory, you won't have all
the sources that make up rt.jar.
Taken from:
http://www.java.net/forum/topic/jdk/java-se-snapshots-project-feedback/it-possible-just-build-rtjar
So when you say javac on all the java files inside src.zip it won't compile as the dependency graph is broken (missing generated files)
Also have a look at this: Where to get full source code for rt.jar?
If you want to change a number of class, you only need to compile those classes. You don't need to compile the whole JDK unless you intend to replace it.
If you just want to patch it, create a JAR of your changed classes and add this to the boot class path.
After revisiting the question. Javac on any of those files will allow you to rebuild them. Also you don't compile .java files into .java files they become .class files. You can write an ANT build script to handle the heavy work for you.

Categories

Resources