Eclipse Class File won't open in java editor? - java

I've been using eclipse a very long time but I've never encountered this problem.
I have a program I'm working with, and normally to navigate between class files you can simply double click the class file under the project explorer, or you can right click and select open with java editor.
This is fine, but randomly, I have a single class file that when you try to do this, nothing happens. If you select open with text editor, the file opens, but it won't open in java editor. Anyone experienced this?

I fixed it by copying the class file. The duplicate opened normally. Thank God.

Q: You have an Eclipse Java project (or J2EE project), correct?
Q: Most of the .java files in your project open with the (context-sensitive) Java editor, correct? And most of the .class files already compiled in your project open with the "Java decompiler", showing the Java byte code instructions for that class, correct?
Q: The problem is that some of the .java (source) and .class (byte code) files don't behave this way, correct? When a file goes "bad", is it always broken for both .java and the corresponding .class file?
SUGGESTION: Try Project, Clean; then "Project validate". See if one or all of the affected files "recover".

Close your eclipse IDE and compile the project from terminal or CMD using mvn clean install -U -DskipTests=true.See if you get any error in compilation then fix it(usually it is due to some indentation error which by mistake got added in java file),if not just lauch your eclipse IDE and open the corrupt java file ,it should open this time without any issue.

Related

I've been coding with notepad++ and now I'm getting into Eclipse IDE and I'm having trouble with my older projects

So,
I have been coding Java last semester (college) and we've always done it in Notepad++ , compile and execute by CMD (very simple programs though) and now I want to start codding in Eclipse, since I heard that it saves you a lot of time in syntax and gives you a heads up on typos and errors (Also I'm tired of compiling and executing by console). But the thing is that I usually have my code into two folders (model and interface) and use the
package modelo;
package interfaz;
And now I execute eclipse and open these files, but it doesn't seem to work, I mean the code shows up and I can edit, but it wont show help or even let me execute the code. I know it must be a very noobie question but I can't seem to make it work.
Update:
This is what i get when i import my "project"
This is the error
The project is not configured as Java project:
Create a Java project via File > Other...: Java > Java Project
Copy the content of the src folder into the src folder of the new project
In the new project, open the class that contains the main method and click the Run button
maybe eclipse didn't figure out which main you want to run.
try right click on Menu.java -> run as -> 1 Java Application
You need to create a project in Eclipse first, then add packages and classes in that project, make sure that the JDK in classpath is configured correctly

Project not appearing in Eclipse's explorer

I am new to Java programming.
Until now, all I was doing was writing the code on eclipse and running the code there only.
However this time i tried to write a code in text editor and run the same through following:
I created a folder named TEMP3 in workspace. (I could see as well the folders of other projects that I directly created on eclipse.)
Created a hello.java file in text editor which outputs "Hello world" and saved that file in the folder TEMP3 created above.
Now I successfully compiled and run the file.
Now when I open eclipse, I expect to see the TEMP3 Project (and in there the hello class) in eclipse's Package Explorer.
But I don't see the TEMP3 folder.
Why is it so?
You could try to import your new folder "TEMP3" and then it should appears.
I'm studying java from middle february 2017 and I can suggest you to use a correct package structure with right names. It helps a lot during programming.
Eclipse projects must contain at least a .project file for Eclipse to recognize them as a project. The folder you have created doesn't contain this file so it isn't recognized.
In addition to this Eclipse won't recognize a project added to the workspace externally until you do a 'File > Refresh'.
So the best bet is to create a Java project inside Eclipse in the normal way and then use 'Import > File System' to import the hello.java file.
Note that the Eclipse Package and Project Explorers normally hide the .project file so you don't see it in Eclipse. In addition on Linux and macOS the OS doesn't show files starting with '.'

Running .jar File Java 8

I've run .jar files before, but I've encountered a "different" situation, and I'm not sure what to do. I'd appreciate if someone could help me out.
Previously, I programmed with Java 6 and Eclipse Juno exported all my programs to runnable jar files. I'd get a .jar file that I could run by just double clicking on it. The files always looked something like this (note the jar file icon):
Recently, I wrote a program in Java 8 with Eclipse Luna (Release 4.4.0) and exported it to a runnable jar file, and I got something different (note the different file icon):
It no longer runs when I double click it. Instead, my computer uncompresses the jar, as it would a zip file. I tried running it from terminal. I cd'd to the directory and typed
java -jar graph3D.jar
I got the following error message:
Error: Unable to access jarfile graph3D.jar
After uncompressing the jar file, I found a folder named META-INF with the manifest file, MANIFEST.MF in it. It was the only file that seemed to resemble an executable file. Do I have to do something with that?
Could someone explain how I can run the second jar file graph3D.jar? Is it something new with Java 8, or something different about Eclipse Luna, or something else?
(Both programs run fine in Eclipse, by the way)
Thanks for your time and help.
Edit:
Below was the dialog box Eclipse displayed if anyone is interested.
Selecting "Use .jar;.zip" makes the filename "graph3D.jar;.jar;*.zip" .
Selecting "Use .zip" makes the filename "graph3D.jar;*.zip"
Selecting "Cancel" doesn't let you go forward.
You'd have to manually delete the extra file extension.
Somehow when you exported the file, the filters for the file dialog box (*.jar;*.zip) got attached to the filename, which is graph3D.jar;*.jar;*.zip, not graph3D.jar. Java can't find it because it doesn't have the name you supplied. Rename the file and pay close attention next time you export; either you fat-fingered something, or you're triggering a significant bug that needs fixing.
I recommend that you will access the build folder after you've built your project on the IDE under your project folder (in your workspace) and copy both the libraries folder and the .jar and post them wherever you want the program to be "installed", you'll then have an executable jar that should run smoothly without problems, just as I said don't forget the lib folder.
I think there is nothing new in Java 8 related with the running jar, I guess you need to check the the Eclipse export issues, it seems your classes are missing from your second jar file.

IntelliJ IDEA Class Files Disappear Upon Compilation

I'm brand new to IntelliJ but have been working with java for years. In IntelliJ IDEA 12.1.6, when I first create a .java file and then compile it, the .class file with the same name appears in the 'out/production' folder just as its supposed to. But if I do anything to the java file to get a compile error, the class file disappears from the folder. Is this some weird setting in IntelliJ? Do I have a bad installation?
This is because IntelliJ is rebuilding automatically when you change the file. To avoid having the files deleted, go to the Compiler section in the Properties (Cmd+, [Mac] Ctrl+Alt+S [Win]) and uncheck the "Clear output directory on rebuild".

Eclipse run old version of program

I have a problem while runing my application in eclipse. I make some edits like this:
String res = "newvalue";
System.out.println(res);
But when I run the application I still receive "oldvalue" in output. After this I tried to delete main() function - and I run application and I see "oldvalue" in output again.
Maybe it's some cache in JVM, or smth. else?
UPD:
It's 15:35 on my clock now. But in /bin folder I see .class files with 14:33 timestamp. I change source files (.java), press ctrl+f11 in eclipse and files in /bin folder are still 14:33 ...
UPD2:
After cleaning the project I receive the following problem:
The project was not built due to "Could not write file: D:\projects\NelderMead\bin\ru.". Fix the problem, then try refreshing this project and building it since it may be inconsistent
SOLUTION
The problem was that eclipse can't write file to the folder with spaces and UTF chars in it's name. So, I copy project to the new clean workspace and it runs without problems! Thx all for help detecting the problem!
You're executing an older class files, the reason could be
a compile error somewhere else (see problems view)
or your changed accidentally the source path so that the new source no longer gets compiled.
Try to clean the project and make sure the new classes are compiled to your output folder.
The JVM doesn't have a cache for class files.
First, make sure the file is saved (there is no asterisk next to the file name in the tab). Usually files are saved automatically, but you could choose not to save files and never ask by mistake, the first time Eclipse pops up this dialog.
Then see what's going on in the Problems view. You might see something like project cannot be built due to the following reason. It may be because of compilation errors in the dependent projects.

Categories