Get an error when making a Hello World program [duplicate] - java

Component Details - Using IntelliJ IDEA 2017.1 CE and jdk-9-ea+154
main() -
Set<String> set2 = Set.of("a", "b", "c");
set2.forEach(System.out::println);
module-info.java
module collection {
requires java.base;
}
Logs -
Error occurred during initialization of VM
java.lang.RuntimeException: Package jdk.internal.jimage.decompressor in both module jrt.fs and module java.base
at jdk.internal.module.ModuleBootstrap.fail(java.base#9-ea/ModuleBootstrap.java:699)
at jdk.internal.module.ModuleBootstrap.boot(java.base#9-ea/ModuleBootstrap.java:329)
at java.lang.System.initPhase2(java.base#9-ea/System.java:1928)
Doubtful over the implementation of initialization of VM, my question is that I haven't included module jrt.fs - Where is it coming in the picture from? How do I debug such modules inclusion/exclusion? How do I further solve the current exception?

I got the same error under Arch Linux. The package java-openjfx installs its libraries into the lib directory of the openjdk, which seems to cause problems.
I found a workaround by adding not the whole lib directory but only the needed libraries instead.
In project structure > Libraries > + > Java > /usr/lib/jvm/default/lib > select needed libraries (holding ctrl)
should look something like this
Then in Run Configurations set the VM Options accordingly
--module-path /usr/lib/jvm/java-14-openjdk/lib/javafx.base.jar:/usr/lib/jvm/java-14-openjdk/lib/javafx.controls.jar:/usr/lib/jvm/java-14-openjdk/lib/javafx.graphics.jar --add-modules=javafx.controls
For my project it was enough to only add controls as module but the path to base and graphics were required to get it to run.

I had the same issue on Manjaro Linux, while it was working fine on windows. Looking at the differences it became clear that the javafx 11 package installs into /lib/jvm/java-11-openjdk/lib, which I then set as PATH_TO_FX. This seems to be the issue, because jrt-fs.jar is in the same folder.
I moved all files from fx to a separate folder and then set that as PATH_TO_FX. Now it works fine.

$JAVA_HOME/lib/jrt-fs.jar contains a copy of the "jrt" file system provider compiled to JDK 8. It's for tools such as IDEs that run on JDK 8 but need to access a JDK 9 run-time image.
From the exception then it does appear that this JAR file, or maybe $JAVA_HOME/lib, has been put on the module path in error. JAR files that do no contain a module-info.class in the top-level directory are treated as automatic modules so this is why the exception has "module jrt.fs" in the message. The exception basically just means that you've ended up with two modules containing the jdk.internal.jimage.decompressor package (and many other packages) due to putting jrt-fs.jar on the module path.

To fix this problem, please follow the below steps.
1- Right-click on your class.
2 - Run AS-> Run Configurations
3. Click on main ->
Click on the Browse option and Choose your project name in project.
Click on the Apply button and after processing click on the Run button.

Try to remove jrt-fs.jar from the directory of jdk9. I did it in Project Structure in IntelliJ IDEA and it works fine for me

In Eclipse, changing the Eclipse workspace or deleting the .metadata folder in the workspace folder worked for me.
I don’t know what fixed it, but if I had to guess it could be something in the .metadata folder that caused the exception.

I faced this issue for Spring Toolsuite 4, The metadata contains info about the present projects in the workspace, and common eclipse settings like font, codestyle, run configurations settings and sometimes information about modules used, eclipse plugins & eclipse log file for eclipse log errors, etc.
It does not contain valuable project info.
If this folder is deleted or changed manually, eclipse sees this directory as a new fresh workspace. You have to import the existing projects again and you are done.
If you want to keep your fonts, codestyle etc you can export / import these preferences for new workspaces or create a backup of .metadata.
In my case it worked for above issue of Package jdk.internal.jimage.decompressor in module jrt.fs and module java.base when i deleted .metadata folder, import project again, setup run configuration and everything started working.

remove the .metadata folder, then restart eclipse.

I had the same issue on a Mac Eclipse Version: 2020-09 (4.17.0)
Whenever I tried to run my existing Configuration I got that error.
I tried all kinds of workarounds but nothing worked.
So I created a new Configuration:
Open file containing main() method.
From Run menu select "Run As >> Java Application"
That ran OK. The advantage of this is that it does not modify your JDK installation.

Removing the .metadata folder in the workspace folder works for me.
(I'm using Windows with Eclipse 2021-06 (4.20.0))

Related

Eclipse Oxygen - The project was not built since its build path is incomplete

I just installed Eclipse Oxygen and tried to open an existing project into the workbench but I get this error:
The project was not built since its build path is incomplete. Cannot
find the class file for java.lang.Object. Fix the build path then try
building this project
I tried right clicking on the project - went to Properties - Java Build Path - Libraries - Add Library - JRE System Library and selected Workbench default JRE (jre1.8.0_60).
I then cleaned and rebuilt the project but it then causes more errors to come up like:
ActionBar cannot be resolved to a type
Activity cannot be resolved to a variable
AdapterView cannot be resolved to a type
ArrayAdapter cannot be resolved to a type
Here is what made the error disappear for me:
Close eclipse, open up a terminal window and run:
$ mvn clean eclipse:clean eclipse:eclipse
Are you using Maven? If so,
Right-click on the project, Build Path and go to Configure Build Path
Click the libraries tab. If Maven dependencies are not in the list, you need to add it.
Close the dialog.
To add it:
Right-click on the project, Maven → Disable Maven Nature
Right-click on the project, Configure → Convert to Maven Project.
And then clean
Edit 1:
If that doesn't resolve the issue try right-clicking on your project and select properties. Select Java Build Path → Library tab. Look for a JVM. If it's not there, click to add Library and add the default JVM. If VM is there, click edit and select the default JVM. Hopefully, that works.
Edit 2:
You can also try going into the folder where you have all your projects and delete the .metadata for eclipse (be aware that you'll have to re-import all the projects afterwards! Also all the environment settings you've set would also have to be redone). After it was deleted just import the project again, and hopefully, it works.
In Eclipse, Right click Project -> Maven -> Update Project. It fixed errors in my project.
I'm also using Eclipse Oxygen, migrated from Mars. I faced the same error. I deleted .metadata, .recommenders folders and added projects from archive and issue is solved. I also use Android Studio but i like Eclipse much more.
At my system the Java Runtime JAR file jrt-fs.jar was not found because it was in the wrong directory. This file should be located in the "lib" subfolder. If you installed Java at "C:\Temp\java" the file should be here at C:\Temp\java\lib\jrt-fs.jar .
These are the steps to make jrt-fs.jar available to Eclipse:
Window / Preferences -> the "Preferences" Window opens
Select in the left menu: Java / Installed JREs
Press the [Add...] Button -> A window opens
Select "Standard VM" - The window "JRE Definition" opens.
Enter your path information:
JRE home = "C:\Temp\java"
JRE name = "MyJRE"
Select [Add External JARs...] to link the jrt-fs.jar
JRE system libaries: "C:\Temp\java\lib\jrt-fs.jar"
It worked for me with OpenJDK12 and Eclipse 2019-09 (4.13.0).
Eclipse reported me this error:
The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project
I had faced this problem. I added the C:\Users\Office 2\android-sdks\platforms\android-19\android.jar to the Java Build Path's Library. And the project started to run again.
The problem occurred due to my carelessness. Yesterday night I was updating the Android SDK, and at the same time I tried to run the project, while the SDK Manager was uncompressing the system image. The Project couldn't start and the error occurred.
I tried all the methods given by others. But nothing worked. It solved when I added the android.jar to the library.
I guessed it that android library is missing. not the Java, when I saw the errors only at the android methods and imports. But when I read the posts, I got confused and wasted some time trying wrong way.
I had faced the same issue and tried different solutions, I have reinstalled my JDK 11 and restarted the machine, after that the issue gets resolved.
I got this out of the blue in a workspace that was working properly before. This problem seems to indicate that the project configuration somehow got corrupted.
Restarting Eclipse didn't help, but in the same vein as the answers dealing with Maven, regenerating the Eclipse project config with:
./gradle eclipse
or
./gradlew eclipse
if you use the wrapper, solved this problem for me.
I have similar issue when importing Spring Boot, jdk 11 (using
inside docker) project to Eclipse 2019 (2021), in Ubuntu, instead when
importing to Inteelij IDEA Community or NetBeans IDEs they do
not produce the same set of after-import errors as in Eclipse.
The Spring Boot is multimodule maven projects and two child
modules give such 2 "problems" in appropriate problems tab:
The project was not built since its build path is incomplete.
Cannot find the class file for java.lang.Object. Fix the build
path then try building this project
Next 2 errors are produced in two classes of aforementioned
maven modules:
The type java.lang.Object cannot be resolved. It is
indirectly referenced from required .class files
Manipulation with adding JDK 11 to submodules buildpath
just leads to the thousands of problems. Also it is
got when I use Eclipse-File-Maven-Update.
Moreover when I try to edit most of existing classes or add new ones
I got red underline that tells
Implicit super constructor Object() is undefined for default
constructor. Must define an explicit constructor
. So almost no opportunity to use Eclipse
even at prebuild stage as docker-compose should run build and
run. Indeed I noted that such issue is produced just when project
also uses modules (module-info files introduced in java9).
When I import project on jdk 8 (even not installed on
system), or even on jdk11 without module-info files all
is fine in Eclipse after import.
Another difference is that of when I use problem old no module
project the Build Path is composed with jre environment 8 and
maven dependency items, but when using
"module-info" project the Build path contains -module path,
and -classpath. So I even do not know where to add jre 11,
indeed adding does not resolve issue, just make more errors.
So what is the resolution of the case??? What settings to do
in Eclipse?

RuntimeException: Package jdk.internal.jimage.decompressor in module jrt.fs and module java.base

Component Details - Using IntelliJ IDEA 2017.1 CE and jdk-9-ea+154
main() -
Set<String> set2 = Set.of("a", "b", "c");
set2.forEach(System.out::println);
module-info.java
module collection {
requires java.base;
}
Logs -
Error occurred during initialization of VM
java.lang.RuntimeException: Package jdk.internal.jimage.decompressor in both module jrt.fs and module java.base
at jdk.internal.module.ModuleBootstrap.fail(java.base#9-ea/ModuleBootstrap.java:699)
at jdk.internal.module.ModuleBootstrap.boot(java.base#9-ea/ModuleBootstrap.java:329)
at java.lang.System.initPhase2(java.base#9-ea/System.java:1928)
Doubtful over the implementation of initialization of VM, my question is that I haven't included module jrt.fs - Where is it coming in the picture from? How do I debug such modules inclusion/exclusion? How do I further solve the current exception?
I got the same error under Arch Linux. The package java-openjfx installs its libraries into the lib directory of the openjdk, which seems to cause problems.
I found a workaround by adding not the whole lib directory but only the needed libraries instead.
In project structure > Libraries > + > Java > /usr/lib/jvm/default/lib > select needed libraries (holding ctrl)
should look something like this
Then in Run Configurations set the VM Options accordingly
--module-path /usr/lib/jvm/java-14-openjdk/lib/javafx.base.jar:/usr/lib/jvm/java-14-openjdk/lib/javafx.controls.jar:/usr/lib/jvm/java-14-openjdk/lib/javafx.graphics.jar --add-modules=javafx.controls
For my project it was enough to only add controls as module but the path to base and graphics were required to get it to run.
I had the same issue on Manjaro Linux, while it was working fine on windows. Looking at the differences it became clear that the javafx 11 package installs into /lib/jvm/java-11-openjdk/lib, which I then set as PATH_TO_FX. This seems to be the issue, because jrt-fs.jar is in the same folder.
I moved all files from fx to a separate folder and then set that as PATH_TO_FX. Now it works fine.
$JAVA_HOME/lib/jrt-fs.jar contains a copy of the "jrt" file system provider compiled to JDK 8. It's for tools such as IDEs that run on JDK 8 but need to access a JDK 9 run-time image.
From the exception then it does appear that this JAR file, or maybe $JAVA_HOME/lib, has been put on the module path in error. JAR files that do no contain a module-info.class in the top-level directory are treated as automatic modules so this is why the exception has "module jrt.fs" in the message. The exception basically just means that you've ended up with two modules containing the jdk.internal.jimage.decompressor package (and many other packages) due to putting jrt-fs.jar on the module path.
To fix this problem, please follow the below steps.
1- Right-click on your class.
2 - Run AS-> Run Configurations
3. Click on main ->
Click on the Browse option and Choose your project name in project.
Click on the Apply button and after processing click on the Run button.
Try to remove jrt-fs.jar from the directory of jdk9. I did it in Project Structure in IntelliJ IDEA and it works fine for me
In Eclipse, changing the Eclipse workspace or deleting the .metadata folder in the workspace folder worked for me.
I don’t know what fixed it, but if I had to guess it could be something in the .metadata folder that caused the exception.
I faced this issue for Spring Toolsuite 4, The metadata contains info about the present projects in the workspace, and common eclipse settings like font, codestyle, run configurations settings and sometimes information about modules used, eclipse plugins & eclipse log file for eclipse log errors, etc.
It does not contain valuable project info.
If this folder is deleted or changed manually, eclipse sees this directory as a new fresh workspace. You have to import the existing projects again and you are done.
If you want to keep your fonts, codestyle etc you can export / import these preferences for new workspaces or create a backup of .metadata.
In my case it worked for above issue of Package jdk.internal.jimage.decompressor in module jrt.fs and module java.base when i deleted .metadata folder, import project again, setup run configuration and everything started working.
remove the .metadata folder, then restart eclipse.
I had the same issue on a Mac Eclipse Version: 2020-09 (4.17.0)
Whenever I tried to run my existing Configuration I got that error.
I tried all kinds of workarounds but nothing worked.
So I created a new Configuration:
Open file containing main() method.
From Run menu select "Run As >> Java Application"
That ran OK. The advantage of this is that it does not modify your JDK installation.
Removing the .metadata folder in the workspace folder works for me.
(I'm using Windows with Eclipse 2021-06 (4.20.0))

Could not find or load main class in STS/Eclipse

I have a main method in a package in one of my projects. Say, the package is com.ant.car. I am trying to run and/or debug this main method, and I keep getting the error Could not find or load main class com.ant.car.
I've searched this problem, and it seems like I can't figure out what is wrong.
1) I've checked run configurations. In Run->Run Configurations, I've checked that the Main class is com.ant.car.
2) I've checked build path. If I right click on the project, I select Build->Build Path, and under the Libraries tab I make sure there are no missing folders with red Xs next to them.
Not really sure what else to do. Any suggestions?
Project -> Clean
this is working
Try updating project by right clicking on it. Maven -> Update Project
Today I ran into the same problem and I tried a lot of answers. Nothing helped. Cleaning the project, build automatically is already checked, deleting .metadata, etc.
Eventually I tried this and it worked perfectly:
menu Project -> Properties
Java Build Path, tab Libraries
Remove the JRE System Library from there, press Add Library, take the JRE System Library and press Next. Workspace default JRE and press Finish.
What worked for me:
Menu Project -> Properties
In Java Build Path, tab Libraries
Delete all libraries with a red [x] next to them.
In my case, problem happened when I switched from Kepler to STS IDE.
The solution to this was the following:
Close Eclipse/STS
Use a file explorer on your operating system to navigate to your workspace (In my case, I'm on Windows so I used Windows Explorer)
Delete the .metadata directory (or to be safe, copy the directory somewhere else to be safe, then delete it)
Restart Eclipse/STS
Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.
Sometimes the problem can be caused by some newly added dependencies. Try removing the recently added jars. That's how I fixed my problem.
Project -> Clean... -> check project not working -> Clean
I already had build automatically set, but forcing STS to rebuild it fixed it.
This issue occurs when the main .class file moved or not found because you changed the directory for committed/shared the project into the git or another repository.
To Resolve this issue -->
Remove existing run configuration and new one.
Find the parent pom.xml or project pom.xml and open cmd/command prompt and run the below commands,
mvn clean install package
mvn eclipse eclipse
It worked for me:
1. Delete metadata from work-space directory.
2. Import the project again, but selected copy to work-space option.
I think the cause for the error was Non-English characters in the original saved directory.
You just need to delete Run Configuration file and restart STS and run command -mvn clean install and try to restart the service
The Error "Could not find or load main class com.ant.car" occur when your class is not in build path. please make sure that .class file is generated and it's in build path ..
I faced the same issue..
just do follow these steps:
STS/Eclipse --> Project --> Enable "Build Automatically"
then refresh your project, it will resolve your issue.
Still not refreshed your projects automatically, just restart your STS and check.
Hope it will help you.
I think .class files are deleted/missing from JavaProject/bin folder.
To resolve this issue ->
1) Just cut paste and save the code contents of all the files that you are using then .class files will be regenerated.
2) Then run the code and you can see it works fine if there is no syntactical errors.
1 ) Clean the Project
2 ) Enable build automatically Option
3 ) Update the maven project by use the short cut Alt + F5
Deleting target folder manually and mvn clean install worked for me
A quick and easy fix is to directly run your SpringBootApplication class (i.e. Right click, Run As -> Spring Boot App). This runs the app and creates a run configuration automatically.
I spent several hours on this issue, finally it is fixed by doing this:
Properties -> Java Compiler: uncheck the checkbox "use '--release' option"
This worked for me to solve the error. (I got this error after removing AWS ToolKit)
Close the Eclipse/ STS Eclipse.
Go to the WorkSpace folder.
Delete the .metadata folder.
Open the eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Remove project from STS/Eclipse
Close or Refresh the Eclipse/ STS Eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Tried above mentioned steps to resolved issue.
You can try one of the two solutions below:
Solution 1: Right click the project -> Gradle -> Refresh Gradle Project.
Solution 2: Add gradle or maven in your environment variable. My problem was that I had not added gradle in my environment variable. Before, make sure Gradle or maven is installed in your OS.
I tried all the answers but finally what worked for me was deleting the project from eclipse workspace and importing it again.

Compile errors everywhere after workspace move

I'm making a webapp in Eclipse. I use to make it in my Desktop. And today I got a laptop and I've copied the workspace in my Desktop to laptop.
And after copying the workspace, I've opened my Eclipse pointing to the copied workspace. And when I opened my Java files, almost every line is red underlined .
In my desktop there was no problem with this app, It used to work fine.
When I started my Eclipse with this copied path, I though the errors were due to the jar files (I used to have jars in my desktop associated to this project).
Even after configuring my Build path, the red lines still appear.
How can I solve this?
A wild guess: The path to the JRE is wrong so the compiler does not find the Java standard library. When none of the standard library classes are found you get compile errors at almost every line.
Solution:
Configure the path to the JRE in the compiler settings:
Preferences → Java → Installed JREs
And/or configure the path to the standard library in the project settings:
Project settings → Java Build Path → Libraries
Edit existing entry for system library or add a new one.
You don't want to just copy the workspace over. You want to import the project into Eclipse. You will also want to make sure that you import, and add, any external .jar files. To import use:
File > Import > Existing Project into Workspace
Did you use the import wizard after setting your workspace (http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-importproject.htm)? This is the important part. Once that's done be sure to do a clean build. If you see errors then, you might still be missing external jars that you had on your desktop.

Eclipse: "The import java.io cannot be resolved"

I have several Android projects in Eclipse, and all is fine, except one (a library) that can not resolve any imports.
The java.io imports do resolve fine in other Android projects in the same workspace, and previously (I haven't used it for over a year) this library worked fine, too.
Any ideas?
Check two things
Eclipse preferences
Check your Eclipse preferences: Java -> Installed JREs
The one that you're using should be marked and it should be a JDK not just a JRE.
Project build path
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the libraries folder whether the JRE System Library is present and ...
If not add it using Add library -> JRE System Library and then
select the correct one (from an installed JDK).
I am using Maven an this is what I did to re-solve -->
Right click on project
Maven -> Update Project. Make sure you choose 'Force update of Snapshots/Releases'.
Also check the 'clean project', 'update project conf from pom' and 'refresh workspace resource options' and click ok.
The following worked for me:
Close the project and reopen it.
OR
Clean the project ( = rebuilds the buildpath and thereby reconfigures the JDK libraries).
I was missing the JRE Systems Library in my Project Tree.
And navigating to Projects' Build Path and 'Add(ing) Library' worked!
I just ran into this problem with Eclipse 2022-6 and java-17-openjdk-amd64. I just appeared during editing in another file, the same code had worked before.
For me, all settings were correct and none of the above tricks worked. What I then did was completely removing the import command import java.io.Closeable;, saving the file, adding the same import command back at the same place, and saving again. The error disappeared.

Categories