advanced Java programmer, newbie to Eclipse (Oxygen.1a Release (4.7.1a)) here.
When I try to run my Java console app [invoking main()], Eclipse doesn't seem to compile the current java file in my editor and copy the class file to the bin directory. Instead, it just runs the same old class file that is already in the bin directory, or if it's not there, complains that "Error: Could not find or load main class MyPackageA.MyClassA". It worked only once, the first time when I created the project and imported the files.
I can edit the java file in a text editor, compile and run it at the command line OK (away from Eclipse). I can even copy the class file(s) to Eclipse's bin directory and 'run' the corresponding java file that's in my Eclipse editor. But it's not the java file that's in my Eclipse editor that is running, nor is it a class file compiled from that java file; it's the class file of the same name that I compiled and copied to the Eclipse bin from elsewhere.
Tutorials and YouTube videos that I have found only seem to show the "happy path" where everything works as one my expect.
Please advise.
I ran Project->Clean... on the project and now it is working; compiles and copies/deploys to the bin directory, executes as expected.
It still gives me an error dialog before executing: "Errors exist in required projects...Proceed with launch?" That doesn't seem to affect the outcome, but I'm worried there be more problems lurking in the shadows.
Thanks to All for your help!
Related
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.
I am constantly facing this error and I have no idea how to fix it.
App.java is not on the classpath of project ss_d36b3017, it will not be compiled to a .class fileJava(32)
I am using Visual Studio Code for writing Java. I have set up the environment variable. javac --version and java --version and giving the expected results in PowerShell. I am using a very simple folder convention than is made by VS Code pallet. It has 1 folder (in drive D:)named project which has 3 folder named lib(This is vacant), src(This has the App.java)<readme.md It has no building tools. Code inside the App.java does not affect the issue.
I need some help.
Try the following two ways to see if question goes away.
Open Command Palette and choose Java: Clean Java Language Server Workspace
Right click the folder src and choose Add Folder to Java Source Path, then reload the window.
///WARNING- I DO NOT KNOW ANY LANGUAGES/HAVE NO USED ECLIPSE BEFORE\\
I'm currently trying to get a .jar file compiled in Java8 to compile in Java7, but seem to be having trouble, I have the source code intact so that is not the problem. It compiles fine, but the finished .jar is smaller than the original by a large margin. I believe the problem lies in my inexperience with Eclipse meaning I problably did something wrong.
Source Folder Structure
src\com\darkblade12\enchantplus...java files
Contents Of Each Folder
If you have some doubts about eclipse being behind the problem, try to compile it directly using the Command line Interface with the target version version of java by using javac.
Example for Windows:
set JAVA_HOME=C:\Program Files (x86)\Java\jre1.7.0_21
javac com/darkblade12/enchantplus/*.java
jar cvf program.jar -C com/darkblade12/enchantplus
Then compare your jar generated by eclipse and this generated directly from the command line.
Another way to verify is to open the jar file with and archive manager like 7-zip and verify its content.
I have been doing a coding exercise inside the IntelliJ IDEA Community Edition 14 IDE, using OpenJDK.
The project is split over 4 .java files all in the same package.
My end goal is to run this in the terminal/bash (I use System.console().readLine() which doesnt play nicely in the IDE's console).
I've tried navigating to the directory where these 4 files reside (they all reside in the same dir) and tried:
javac -classpath . BibliotecaApp.java Book.java BookManager.java LibraryDB.java
This creates 4 corresponding .class files fine.
The Main is in bibliotecaApp.java/class, so I try run it by:
java BibliotecaApp
But I get the error
Exception in thread "main" java.lang.NoClassDefFoundError: BibliotecaApp (wrong name: com/twu/biblioteca/BibliotecaApp)
Plus about 13 lines of specifics.
Now googling this error seems to be a class path problem, and this is where I get stuck.
From places I've read, usingecho $PATH gives me:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
This is still from the directory of the .java files above.
That path means nothing to me. I have no idea what it is or what it does, or what even a classpath is! Theres alot of resources out there on setting a classpath, but they aren’t helping me because I don't know what it's meant for.
That was a dead end for me. I tried to create a .jar instead using IDEA's Build Artifacts as seen HERE. It created a .jar file but when I navigate to that directory and try run it via:
java -jar biblioteca_jar
I get
Error: Invalid or corrupt jarfile biblioteca_jar
Another issue is that in the file explorer, the file actually comes out as biblioteca.jar, but ls on that dir shows biblioteca_jar. Is that normal?
The code is on my GitHub if that helps anything
https://github.com/botagar/twu-biblioteca-JohnGeddes
Based on your compiler step, change this
java BibliotecaApp
to
java -cp . BibliotecaApp
Which will add the current directory to the classpath for the java runtime environment. See also the Oracle Technote Setting the Class Path.
A jar file is a kind of zip, and should have a .jar extension. So this
java -jar biblioteca_jar
should probably be
java -jar biblioteca.jar
And you can check if the file is valid with any zip archive reader. Including jar itself,
jar tvvf biblioteca.jar
Edit
Based on your comments below,
cd ~/Documents/ThoughtWorks Uni/TWU_Biblioteca-master/src/
and then
java -cp . com.twu.biblioteca.BibliotecaApp
My project runs fine from Eclipse.
But when I tried to make it into a jar file or executable file it doesn't work.
I used the option "Export-Runnable JAR file"
The following message appears just after the eclipse finished the exporting process
JAR export finished with wornings , see details.
the details were ..
Exported with compile warnings:Mario/src/Map.java
and the same for other classes like
Exported with compile warnings:Mario/src/Player.java
and so on.
So that I used the other option "Export - JAR file"
It works fine and nothing appears while exporting it from Eclipse.
But when I try to open the file it gives me
Couldn't find the main class:Frame.Program will exit
Somebody have any idea about what the problem is?
Your MANIFEST.MF file inside the META-INF dir should have a Main-Class attribute pointing to your main class.
The important thing for executable jar is Manifest. Make sure it exists and points to the correct class with main method