vscode debug pauses on decompiled .class file instead of source .java files - java

This has been bothering me for quite some time and i have yet to find a solution.
When I set a break point in VSCode for debugging java the debugger pauses on the .class files located in the maven target/classes instead of the .java file.
I would like it to use .java just like the way Intellij does it. Its really annoying for me when I find my bug and edit the code then hit replay only to find I edited the code in the .class file instead of the .java. The .class file gets overwrite on the next debug play and you lose all the changes you've just made.
I have found this link below on github that asks the same question but there is no answer
https://github.com/microsoft/vscode-java-debug/issues/915
I am using the Microsoft java extension pack.

Related

Why does VSCode keep opening *.class files as opposed to .java files?

(I couldn't figure out how to upload my screen capture to stackoverflow. So this is a streamable link: https://streamable.com/0im8tx)
In this video, VSCode opens QueriesController.class as opposed to QueriesController.java when I cmd click into QueriesController.
I have compiled provided the definitions of the jar file in my workspace:
"settings": {
"java.project.referencedLibraries": {
"include": [
"<path-to-jar-that-contains-QueriesController.jar>",
....
"sources": {
"<path-to-jar-that-contains-QueriesController.jar>": "/my/local/java/definition/src/folder",
Does anyone know why VSCode is choosing to open the definition as a .class file rather than a .java file?
I use commands to generate a simple jar package and use it in another project. It's true that when we click the class name, .class file is opened instead of .java file:
About how to generate a executable jar package, you can have a look at this reply:
Compile .java file and generate .class;
Generate manifest and pack them into jar
In general, a JAR (Java ARchive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution.
.java file isn't included in jar packages, and that's why you get .class file opened instead of .java file.
I am not familiar with VSCode but your problem is common across most IDEs.
Usually when a jar is made, it consists of compiled class files rather than original source codes. The reason for this is to run code as efficient and fast as possible and usually people don't want source code in jar because when running they also have to be recompiled again which is a waste of time.
Take a look at this picture. I have just downloaded a jar file from mavenrepository and it downloads the compiled version of jar. The extension is .class
What the IDE does is it tries to decompile the code with a decompiler (In this case as you can see FernFlower decompiler).
However it lacks formatting and in-code documentation the source code (.java) has. Which is why most IDEs offer to download sources. Intellij shows this right on top. Other IDEs may have this setting buried in deep. (You may have to check for yourself)
When you download sources, IDE try to contact the server and download original source code. Probably that would look something like this:
If you look closely you can see name has changed to .java which represents the source code.
VS Code has option under Java Settings, Java Download sources and Maven download sources.
It is not enabled by default. Upon enabling it, VS Code shows the proper source file, although the name appears to be .Class files.(Upon Ctrl + Clicking the symbol, with method implementations, comments, etc.,JavaDoc Comments)
If proper sources are not found in m2 repository, it shows the decompiled class file with stubbed methods. A comment similar to this is shown at the beginning of the file.
// Failed to get sources. Instead, stub sources have been generated by the disassembler.
// Implementation of methods is unavailable.
In Either of the cases, VS Code shows the maven library files as .Class files in read-only mode. Also, source files are not displayed on the Java Project Explorer.(Although even if it exists in the local .m2 repos).
Hope that helps! Happy Coding!

VSCode java how do I set the path for the compiled .class files to go?

I'm using the Java Test Runner extension in VScode, and I want it to compile my classes to a specific folder. I found the setting to change the -cp when actually running the compiled .class files, but the whole thing still fails since the extension builds the .class files in an obscure temporary folder deep in it's appdata folder.
I would like it to compile my .java classes into a folder I have within my project, so that I can have them there. I have tried googling the sh*t out of this and either I have no idea what I'm saying or noone has ever had a problem with this before.
Thanks in advance for the help.
This is a late answer, but I just ran into this so I hope it helps others.
As of Feb 4, 2021 there is now a setting for the Java Language Support for VS Code extension, where you can specify the output directory for compiled .class files. If you're using VS Code to run Java I'm almost certain you'd have this extension installed.
Simply open your VS Code settings and search for java.project.outputPath. As you'll notice, it states this setting only applies for Workspace settings, not User settings. So make sure to switch to the Workspace tab before clicking Edit in settings.json. This will edit the settings.json file in your projects .vscode folder.
Also note this doesn't work for projects managed with Maven/Gradle. It's great for simple projects though.
For the curious: link to the GitHub pull request where the feature was added to the extension (also has a neat gif of feature in action): https://github.com/redhat-developer/vscode-java/pull/1694
https://blog.usejournal.com/visual-studio-code-for-java-the-ultimate-guide-2019-8de7d2b59902
Under "Adding Libraries and JARs"
First of all,
you can create a CLASSPATH location in your environment variable section, after you set your path location.
Also, what people usually mistake is that they install a code runner used to compile and run all the languages, so if you are running your java code through the top-right run button,
then click on the drop down menu beside it and click the "run java" button and I guess then your code will run just fine.(if you have downloaded java runner extension separately)
I hope this helps!

Access .java src files in Reference Library that don't have .class files

I'm using Eclipse 3.8.0 on OSX 10.7.5 and I'm trying to run jzy3d-9.0 (a 3d graphing package). There are at least two libraries that I need import. The first library came in both .class and .java files, which I was able to add to my reference library successfully. The second library has only .java files and there seems to be a problem related to that. Can I make a reference library without the .class files?
I've tried working around that solution by including the .java files in the build path, but each file has a package declaration at the top which creates an error for each file.
This is an example of code I would like to run. Just above where I highlighted in the code is import org.jzy3d.chart.Chart, which is from the first library, so I know it has loaded successfully. The line I highlighted shows that org.jzy3d.chard2d.Chart2d, which is from the second library, can not be accessed.
In the resource tree, the first highlighted line shows the successfully loaded first library while the second and third highlighted lines show my attempts at loading a library from files and
This next picture shows the chart2d source file and the problem with the package name. The files in the first library all begin with the same type of package declaration, but they work fine.
EDIT: I tried compiling one of the .java files with javac Chart2d.java in the command line, but it can't find the other referenced files, such as Chart.java. Is there a way to compile the whole lot of them together?

decompiled .class file,btyecode version

I am trying to run the source code taken from online. the problem shows decompiled .class file, bytecode version:46.0 (java1.3 or older)
This is not error. It is just android studio telling you that the code you see might not be completely correct, because its decompiled from the class file. You should rather use the .java files in your project, because this is the correct not yet compiled java file format.

Cannot open java programs I saved in eclipse

I had no problem running my java code in eclipse last week and I have no problem creating a new java application in eclipse. However, I am unable to open any of the java program files in eclipse that I saved. I checked to see if my jdk se development kit was removed from my computer by mistake and it is still there. What do you think is wrong? Why can't I open my old files? All of my java programs are saved as CLASS files.
Source files are normally saved with a .java extension. Once you compile your source files, javac will generate you some files with a .class extension. These are not source files, and are usually deleted and recreated every time you compile your code. If you want to find your source code, you'll need to look for the .java files on your disk.
If you've deleted your .java files by accident, it is usually possible to decompile the class files into something resembling the original source, but much of the original formatting will be lost - comments etc. This approach is far from ideal, but may help you recover the situation if you cannot recover the original source files. A good decompiler can be found at http://jd.benow.ca/ - you can either download the standalone application, or it has plugins for Eclipse and IntelliJ.
Hi once you compile the source java files .java extn the class files will be created. Check your workspace in your disk there will be a folder as package as you created in eclipse under src folder.

Categories

Resources