Eclipse Debugger throwing Source Not Found Error - java

I'm using Eclipse to debug a Java program I'm developing. Upon stepping into an insert method of one of my classes called from another class I get a source not found error. I have no idea why because when I hit F3 to go to the class' definition it does so without a problem. I'm using Eclipse Kepler

The class in question is found in a jar file on your classpath and jar files do not correspond to editable source. (but it may have a read-only source zip file attached).
This is most likely because the jar file is placed before the project containing the class on the launchers build path.
Fix your build path.

Related

How to edit .java files imported in Eclipse from a .jar file

I have a question, perhaps it was already answered, but i didn't manage to find it and I appologize if the solution already exists (let me know if it is before deleting my thread).
Problem is:
I have created a program on another PC and exported it from eclipse as a .jar file. It works on my main PC when I double click on it but when I import it in Eclipse I can't find the .java file. So i can't edit it.
What I have done so far:
In eclipse I have created a new empty project
I have right clicked,import, archive file, selected the .class files that eclipse sees, but when I am in the Project Explorer in Eclipse I can't find the .java file where the main is. I mean I can click run as a program and it works, but there is no .java file, only .class files. What am I doing wrong?
That cranes.class should be cranes.java. At least on my other PC it is.
Program works fine, but I can't edit it on my main PC. What am I doing wrong?
Thanks and best regards
You need to select the Export Java source files and resources option while creating the jar file and then your Java files will be available on importing the project from the jar file.
This is similar to how you use other libraries. You depend on the Jar file which contains class bytecode (compiled) of java code. You can't edit any of such files directly in the project you are using it. Thought you can always extends functionalities in your current project using simple inheritance concepts.
If you think such functionalities are trivial you should prefer to change in the original project rebuild the jar and use the newer version of jar.
However if you feel similar things for 3rd party library you can
always make changes after taking fork from those library source
code (if open source) and build and use your own version or go
ahead and raise pull request if you are confident about your
changes.
Mostly when you build a jar file, all you have in it are .class files; these are the result of compiling .java files, and so are not editable with text editors.
You CAN create a jar file that contains .java (also known as source) files, and even a jar file that contains both .java and .class files, but if you ask eclipse to create a jar file, by default it is just going to put .class files and files from resource folders in it, not .java files.
Assuming from the question, the jar is a library created by OP, by compiling java files into class files and packing/exporting them. Although the class files can't be edited in any IDE, they can be de-compiled into Java files by using third-party applications.
I personally use IntelliJ for this de-compiling source files authored by me
Note: Although this gives OP the desired functionality, it may lead to violations if the classes are Copyrighted.
As IntelliJ states, they neither encourage nor discourage de-compiling class files and the decision is purely to the user's discretion.
EDIT: It is always recommended to use the original source files for editing. Try to host them on git so that it may be retrieved anytime required
It may be simpler to not use eclipse but jar/zip/tar your project directory on the one computer and simply extract it onto the other, then open that folder as a new project in Eclipse.
Best is the suggestion from #SanjayBharathi to use git and clone the repo on your other machine.

Java: external archives not accesible

I am working on a class within a package within a source folder within a project with Eclipse Version: 2019-06 (4.12.0).
First I did not organize my files well, so I had to move them using Refactor --> Move. Now I created a class within a source folder. On that particular source folder I right clicked and choose Build Path --> Add External Archives, I then selected a UI library and all worked well.
Now I reorganized my classes and moved them to a different project, where I created source folders and packages for the classes. All the classes work well, expect for the one that uses the UI interface. But here is the part that puzzles me: I can not add an external archive anymore. When I right click on the project, I find Build Path --> Configure Build Path as the only option. Now I can select Libraries and choose Add extneral JARs, but this does not make the class work as it did before. In stead, I get errors on all the lines referencing the UI, saying: the type *** is not accessible or *** cannot be resolved to a type and even line where I do not use the interface but simply introduce a string give an error: The type java.lang.String is not accessible.
I am new to Java and completely puzzled. Any help would be much appreciated.
I found the bug. Apparently there was a package-info.java file created in another package which was in the same source project. This, for some reason, blocked the UI-interface. After deleting this file and removing the JRE System Library from Build Path --> Configure Build Path, then adding the exact same JRE System Library fixed the problem.

Debug point in Eclipse going in .class file

In Eclipse have an Ant project A. For this project in the lib folder by adding a jar, added a dependency of other Java Project B. When I add debug breakpoint in the Java project B, it goes in the .class file instead of .java file.
Also in the .class file during debug if we try to see the details at break point it gives following
Cannot make a static reference to non static field
In the debug view added the source folder of the Project B but still facing same issue. How can this be resolved
As you have added a jar file. That means the project has reference to only the jar file which contains only the pre-compiled class and not the actual source codes.
To have the access to the source codes, add a dependency using the other project as a library project in eclipse.
This way while debugging you will have access to the actual source code.
Make sure you remove the jar file before doing this and also do a clean rebuild to avoid and redundant references.
When eclipse opens the break point on the .class file you need to locate the jar file and then map the sources of the jar. By doing so it does not matter to where the breakpoont is mapped. Eclipse will then open the relevant sources.

Main class not found, IntelliJ building a jar

I am running into problems when I try to run the jar file created in IntelliJ.
I followed the steps laid out here: How to build jars from IntelliJ properly? and searched far and wide for other people with the same problem using IntelliJ, and found no solution.
In the menu Project Structure>Artifacts section I have the package and main class name, and I have also tried specifying the 'Class path' bit using a relative and absolute path both to the source file and the .class file (which seems hidden in the IntelliJ Project display tree..), but even with all this (I also make sure to rebuild the jar every time I change something) I get the "Cannot find the main class. Program will exit." message when I try to run the jar.
In the main project folder, there is src and out.
out contains 'production' with the package tree and the class files
out also contains 'artifacts' with the jar folder and jar executable
src contains a folder of images, the META-INF and the package tree.
the first folder in the package contains the main class, so src/ravelDemo/RavelDemoMain.java
in Project Settings>Artifacts, the main class is listed as ravelDemo.RavelDemoMain
currently, the class path is out\production\RavelSequence v1.03\ravelDemo\ but this and every other class path I've specified (or left blank) doesn't seem to point to the right place. (RavelSequence v1.03 is the name of the project).
What am I doing wrong?
Basing on the discussion is the comments above it appears that IntelliJ IDEA is building the valid executable jar with the main class correctly specified in the Manifest, this jar works fine when executed with java -jar ... command from the command line using the project target JDK version on the user's machine.
The problem is that it doesn't work on double click on #sideways8 system. It may be caused by the corrupted default Java installation or wrong .jar file type association in Windows registry. This is machine specific issue as I have no problem running the shared project jar on my system by double clicking on it.
To fix this problem you can try to uninstall all the Java versions present on this machine from the Control Panel | Programs and Features, then install new JDK from scratch so that it's the only JDK on the system and .jar file type is handled by it.
I use Total Commander which has a nice feature to check/edit file associations (File | Associate With...), here is how the .jar association is displayed when I press Edit type...:
I had the same problem. Either the jar file was created with IntelliJ IDEA or other IDE. I found out the problem in my case that I had two version of java installed on my computer (java 6 & java 8).
It's a problem of misconfiguration of the system. so remove any version of java you have and install it again and the problem is solved.

Error during creating jar file in Eclipse

I d' like to create a jar file. In Eclipse I go to file -> Export. But, unfortunately I get an error:
... is not on its project's build path. Unable to get package fragment root...
I think you might miss a JAR that you're using through imports, you've to fix your Java build path.
To do that, right click on the project, choose Properties, select Java Build Path, click on Libraries tab, Add JARs, add the missing JAR.
If it doesn't work try to restart Eclipse as well and give us a little more context.
I experienced same error while exporting prepared class files through .jardesc (stored export description). Export was adding a lot of prepared class files (so no source .java files) to jar. Due to some changes to java build path source files have been added next to prepared class files. This caused that export did not use given class files. Removing source files fixed error. I had to fix java build path then to prevent source files appearing next to prepared class files again.

Categories

Resources