When I try to make a simple module in IntelliJ it responds with:
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
lospejos
1,9663 gold badges19 silver badges34 bronze badges
asked Jun 15, 2010 at 22:10
Somehow the JDK language jars were removed from the classpath. All I had to do was reapply the JSDK home path.
Goto:
File -> Project Structure -> Platform Settings -> SDKs
Re-apply the JSDK home path.
Doing this added about 15 jars to the classpath. Apparently these are important for compiling.
answered Jun 15, 2010 at 22:32
BrigBrig
10.1k12 gold badges47 silver badges70 bronze badges
22
File -> Project Structure -> Platform Settings -> SDKs, remove existing SDK and add it again.
Works for me in IntelliJ 2017.3.
answered Jan 13, 2018 at 15:09
Babken VardanyanBabken Vardanyan
13.3k12 gold badges65 silver badges86 bronze badges
1
This error happend to me after i’ve updated my JDK version to jdk1.8.0_161 —
But the project’s sdk was still pointing to the old jdk 1.8.0_131
(Seems that updgrading java causing the previous version to be wiped).
Do this:
- In the IntelliJ IDE go to File > Project Structure, from there:
-
Within
Platform Settings > SDKs
:
Make sure that the JDK Home path field is pointing to a valid JDK folder (add a new entry if needed e.g. jdk1.8.0_161). -
Within
Project Settings > Modules
:
Make sure that the Module SDK is set to the same entry you picked in thePlatform Settings > SDKs
- Save & Build again.
answered Feb 14, 2018 at 11:51
MercuryMercury
6,8552 gold badges40 silver badges51 bronze badges
This worked for me:
In Preferences Build Tools > Maven > Runner > Environment Variables
set JAVA_HOME
to your JDK home path.
Usually you want to use the same Java JDK you are using in IntelliJ. You can find that under Project Structure > Platform Settings > SDKs
under JDK home path
.
e.g. /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
answered Oct 28, 2017 at 0:15
Andrea BergonzoAndrea Bergonzo
3,4334 gold badges19 silver badges30 bronze badges
In Intellij Community 2019.1, this is what I did to solve the issue
- Project Structure > Platform Settings > SDKs
- Removed all existing SDKs listed ( I had multiple SDK listed there)
- Add the required SDK only and Apply
answered Oct 8, 2020 at 14:21
- File > Project Structure
-
JDK home path : PASTE_THE_JDK_LOCATION (Like here in the «Project Structure screen shot»
-
Build Again
Cheers
answered May 26, 2018 at 16:54
KumarKumar
514 bronze badges
0
After following this answer,
I learned that %LOCALAPPDATA%/IDEA/config/options/jdk.table.xml
contained incorrect entries. Fixing the JDK table fixed the problem.
answered Feb 11, 2016 at 16:59
DerMikeDerMike
15.1k13 gold badges50 silver badges62 bronze badges
When I try to make a simple module in IntelliJ it responds with:
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
lospejos
1,9663 gold badges19 silver badges34 bronze badges
asked Jun 15, 2010 at 22:10
Somehow the JDK language jars were removed from the classpath. All I had to do was reapply the JSDK home path.
Goto:
File -> Project Structure -> Platform Settings -> SDKs
Re-apply the JSDK home path.
Doing this added about 15 jars to the classpath. Apparently these are important for compiling.
answered Jun 15, 2010 at 22:32
BrigBrig
10.1k12 gold badges47 silver badges70 bronze badges
22
File -> Project Structure -> Platform Settings -> SDKs, remove existing SDK and add it again.
Works for me in IntelliJ 2017.3.
answered Jan 13, 2018 at 15:09
Babken VardanyanBabken Vardanyan
13.3k12 gold badges65 silver badges86 bronze badges
1
This error happend to me after i’ve updated my JDK version to jdk1.8.0_161 —
But the project’s sdk was still pointing to the old jdk 1.8.0_131
(Seems that updgrading java causing the previous version to be wiped).
Do this:
- In the IntelliJ IDE go to File > Project Structure, from there:
-
Within
Platform Settings > SDKs
:
Make sure that the JDK Home path field is pointing to a valid JDK folder (add a new entry if needed e.g. jdk1.8.0_161). -
Within
Project Settings > Modules
:
Make sure that the Module SDK is set to the same entry you picked in thePlatform Settings > SDKs
- Save & Build again.
answered Feb 14, 2018 at 11:51
MercuryMercury
6,8552 gold badges40 silver badges51 bronze badges
This worked for me:
In Preferences Build Tools > Maven > Runner > Environment Variables
set JAVA_HOME
to your JDK home path.
Usually you want to use the same Java JDK you are using in IntelliJ. You can find that under Project Structure > Platform Settings > SDKs
under JDK home path
.
e.g. /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
answered Oct 28, 2017 at 0:15
Andrea BergonzoAndrea Bergonzo
3,4334 gold badges19 silver badges30 bronze badges
In Intellij Community 2019.1, this is what I did to solve the issue
- Project Structure > Platform Settings > SDKs
- Removed all existing SDKs listed ( I had multiple SDK listed there)
- Add the required SDK only and Apply
answered Oct 8, 2020 at 14:21
- File > Project Structure
-
JDK home path : PASTE_THE_JDK_LOCATION (Like here in the «Project Structure screen shot»
-
Build Again
Cheers
answered May 26, 2018 at 16:54
KumarKumar
514 bronze badges
0
After following this answer,
I learned that %LOCALAPPDATA%/IDEA/config/options/jdk.table.xml
contained incorrect entries. Fixing the JDK table fixed the problem.
answered Feb 11, 2016 at 16:59
DerMikeDerMike
15.1k13 gold badges50 silver badges62 bronze badges
I’m getting this error
Error:java: Fatal Error: Unable to find package java.lang in classpath or bootclasspath
in IntelliJ when I try to build/compile any project. Something that should be stated here is that NetBeans, Eclipse and even the javac command line can compile, build, and execute the same project without errors. This is why I suspect that the problem lies with IntelliJ, all other IDEs work well.
In IntelliJ I already:
In Windows I already:
I already seached for issues like this on the Internet, here on Stack Overflow I found:
Question #1 | Question #2 | Question #3 | Question #4 | Question #5
And 30+ sites, and tried every answer…
Here you can see my IntelliJ Project Structure the last time that I tried to build/compile
I was using Java 1.8 when I got this error, after some hours, I installed Java 1.7 and the project worked fine. Maybe IntelliJ doesn’t support Java 1.8?
Anyway, it would be great if anyone knew a way to make Java 1.8 work with IntelliJ.
asked Jun 1, 2014 at 21:10
4
I just spent quite few hours on this and found a solution which might work for you as well. IntelliJ seems to have a bug which expects the JDK to be in a different directory than is specified. I followed these steps:
- open intelliJ, click help -> show log in explorer
- modify build-log/build-log.xml and change
<priority value="info" />
to<priority value="debug" />
, you may have to run the editor as an administrator - run the compilation which fails with «Error:java: Fatal Error: Unable to find…»
- open build-log/build.log and search for rt.jar, you should find it in a block with a set of other JRE libraries and the directory which points to the file should be wrong
In my case the JDK is included in D:Developmentsoftwarejdk1.8.0_20, while the log points to C:UsersVladimirDevelopmentsoftwarejdk1.8.0_20
I fixed the issue by copying my JRE to the place which is expected in the log. And just like in your case this seems to only happen with JDK 1.8.
DerMike
15.1k13 gold badges50 silver badges62 bronze badges
answered Aug 23, 2014 at 17:37
Vladimír SchäferVladimír Schäfer
15.3k2 gold badges49 silver badges70 bronze badges
2
The problem comes from IntelliJ bug (existing at least in version 14).
It happens when your JDK directory is under the user profile directory. For example, JDK located in this directory (for Windows):
C:Usersmyuserjdk1.8.0_20
will be stored in IntelliJ internal configuration (file ‘jdk.table.xml’) as:
$USER_HOME$jdk1.8.0_20
But your %USER_PROFILE% environment variable could point at some other (non default) location. Then IntelliJ will look at the wrong directory.
Possible fix:
Install your JDK at different directory, which is outside your profile directory. Like:
C:Programsjdk1.8.0_20
Then register this JDK for use in your IntelliJ project settings.
answered Mar 18, 2016 at 18:48
1
I encountered this on Arch Linux 4.16.13 with IntelliJ 2018.1.4 after importing a Java project using Gradle. I made sure that there is a registered JDK in «Project Settings» -> «Project» but IntelliJ was unable to find the classes from the JDK, java.util.List
for example.
The solution was to add a new JDK entry at the same path as the existing JDK (/usr/lib/jvm/java-8-openjdk
in my case). This will cause IntelliJ to put the files under jre
onto the classpath whereas with the old JDK entry, only the files under lib
were on the classpath.
answered Jun 12, 2018 at 15:59
Matthias BraunMatthias Braun
30.6k21 gold badges141 silver badges165 bronze badges
Had the same problem. Simple fix to others in case the other answers are complex.
Go to File -> Project Structure
Under Project SDK, choose new and add another JDK.
The default use in my case was 1.8 that was of build 181. I choose the 1.8.0_192 I had recently downloaded.
After applying, the project loads itself.
When I re-ran the test, it works!
answered Dec 9, 2018 at 5:10
1
If this problem occurs when importing a project in netbeans then try to create a new project then check the properties of your new created project and match those properties with the project that you imported in my case there was a difference between target of android package version.
answered Jul 31, 2014 at 9:08
A.Aleem11A.Aleem11
1,81614 silver badges12 bronze badges
1
From what I understood, debugging for hours, the problem is with the location where the jdk1.8 gets installed(/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home), instead of under System/Library).
So the following has to be done to fix in intellij
1. For an existing project, right click and select module settings, and SDK and add 1.8 as a version.
2. Using a terminal go to ~/Library/Preferences//options/. Remove the old JDK specific lines in jdk.table.xml. Update the default version in project.default.xml
Clean you project in intellij and build. It should use the new jdk and sync.
answered Dec 21, 2016 at 0:10
shazzingshazzing
4314 silver badges4 bronze badges
Hi, I am trying to integrate gradle-retrolambda in my Android project, but I am getting the following error when I run my gradle build
:app:compileDebugJava
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
Stacktrace:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:compileDebugJava’.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
….
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:47)
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:38)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJav
I thought it was strange, that it uses the jdk6.Jdk6JavaCompiler although I configured for Java7 compatibility, see below.
Gradle version info:
————————————————————
Gradle 1.12
————————————————————
Build time: 2014-04-29 09:24:31 UTC
Build number: none
Revision: a831fa866d46cbee94e61a09af15f9dd95987421
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy: 2.2.0
JVM: 1.8.0_11 (Oracle Corporation 25.11-b03)
OS: Linux 3.13.0-32-generic amd64
Java environment paths:
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JAVA8_HOME=/usr/lib/jvm/java-8-oracle
JAVA7_HOME=/usr/lib/jvm/java-7-oracle
Gradle build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'me.tatarka:gradle-retrolambda:2.2.1'
}
}
repositories {
mavenCentral()
flatDir {
dirs 'prebuilt-libs'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion "Google Inc.:Glass Development Kit Preview:19"
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 20
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
// gcm (old client library)
compile fileTree(dir: 'libs', include: ['*.jar'])
// auto factory (https://github.com/google/auto/tree/master/factory)
compile 'com.google.auto.factory:auto-factory:0.1-beta1'
// auto value (https://github.com/google/auto/tree/master/value)
compile 'com.google.auto.value:auto-value:1.0-rc1'
// dagger
compile 'com.squareup.dagger:dagger:1.2.0'
provided 'com.squareup.dagger:dagger-compiler:1.2.0'
// butterknife for view injection
compile 'com.jakewharton:butterknife:5.1.1'
// javax annotations (needed for auto generated files)
compile 'javax.annotation:jsr250-api:1.0'
// google guava
compile 'com.google.guava:guava:17.0'
// support library
compile 'com.android.support:support-v4:20+'
// google zxing barcode reader
compile 'com.google.zxing:core:2.3.0'
// progress bar - https://github.com/w9jds/GDK-ProgressBar
compile 'com.w9jds.gdk.progresswidget:library:1.0@aar'
// espresso - https://github.com/JakeWharton/double-espresso
androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'com.squareup.dagger'
exclude group: 'com.android.support'
}
}
apply plugin: 'retrolambda'
retrolambda {
jdk System.getenv("JAVA8_HOME")
oldJdk System.getenv("JAVA7_HOME")
javaVersion JavaVersion.VERSION_1_7
}
Just to verify my java8 installation, I created a gradle project in intellij without retrolambda, and that works fine.
Do you have any idea, what might go wrong here and how to fix it?
Hi,
I am trying to build my project using ant tool, but it is erroring out as follows:
Buildfile: D:My SoftwareeclipseworkspaceShoppingCartbuild.xmlprepare:compile: [javac] Compiling 2 source files to D:My SoftwareeclipseworkspaceShoppingCartbuildWEB-INFclasses [javac] Fatal Error: Unable to find package java.lang in classpath or bootclasspath BUILD FAILEDD:My SoftwareeclipseworkspaceShoppingCartbuild.xml:46: Compile failed; see the compiler error output for details. Total time: 1 second
Please find the build.xml:
<project name="Shopping Cart" default="compile" basedir="."> <property name="app.name" value="ShoppingCart" /> <property name="app.path" value="/${app.name}" /> <property name="app.version" value="0.1-dev" /> <property name="build.home" value="${basedir}/build" /> <property name="catalina.home" value="C:Program FilesApache Software FoundationTomcat 5.0" /> <property name="dist.home" value="${basedir}/bin" /> <!--<property name="docs.home" value="${basedir}/docs" /> --> <property name="manager.url" value="http://localhost:8080/manager" /> <property name="src.home" value="${basedir}/src" /> <property name="web.home" value="${basedir}/web" /> <property name="lib.home" value="${basedir}/WEB-INF/lib" /> <target name="all" depends="clean,compile" description="Clean build and dist directories, then compile" /> <target name="clean" description="Delete old build and dist directories"> <delete dir="${build.home}" /> <delete dir="${dist.home}" /> </target> <target name="prepare"> <!-- Create build directories as needed --> <mkdir dir="${build.home}" /> <mkdir dir="${build.home}/WEB-INF" /> <mkdir dir="${build.home}/WEB-INF/classes" /> <!-- Copy static content of this web application --> <copy todir="${build.home}/web"> <fileset dir="${web.home}" /> </copy> <!-- Copy external dependencies as required --> <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** --> <mkdir dir="${build.home}/WEB-INF/lib" /> <copy todir="${build.home}/WEB-INF/lib"> <fileset dir="${lib.home}" /> </copy> <!-- Copy static files from external dependencies as needed --> <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** --> </target> <target name="compile" depends="prepare" description="Compile Java sources"> <!-- Compile Java classes as necessary --> <mkdir dir="${build.home}/WEB-INF/classes" /> <javac srcdir="${src.home}" destdir="${build.home}/WEB-INF/classes" bootclasspath="${lib.home}" source="1.5"/> <!-- Copy application resources --> <copy todir="${build.home}/WEB-INF/classes"> <fileset dir="${src.home}" excludes="**/*.java" /> </copy> </target> <target name="dist" depends="compile" description="Create binary distribution"> <!-- Copy documentation subdirectories <mkdir dir="${dist.home}/docs" /> <copy todir="${dist.home}/docs"> <fileset dir="${docs.home}" /> </copy> --> <!-- Create application JAR file --> <jar jarfile="${dist.home}/${app.name}-${app.version}.war" basedir="${build.home}" /> <!-- Copy additional files to ${dist.home} as necessary --> </target> </project>
thnx,
Rakesh
I’m getting this error
Error:java: Fatal Error: Unable to find package java.lang in classpath or bootclasspath
in IntelliJ when I try to build/compile any project. Something that should be stated here is that NetBeans, Eclipse and even the javac command line can compile, build, and execute the same project without errors. This is why I suspect that the problem lies with IntelliJ, all other IDEs work well.
In IntelliJ I already:
In Windows I already:
I already seached for issues like this on the Internet, here on Stack Overflow I found:
Question #1 | Question #2 | Question #3 | Question #4 | Question #5
And 30+ sites, and tried every answer…
Here you can see my IntelliJ Project Structure the last time that I tried to build/compile
I was using Java 1.8 when I got this error, after some hours, I installed Java 1.7 and the project worked fine. Maybe IntelliJ doesn’t support Java 1.8?
Anyway, it would be great if anyone knew a way to make Java 1.8 work with IntelliJ.
6 Answers
I just spent quite few hours on this and found a solution which might work for you as well. IntelliJ seems to have a bug which expects the JDK to be in a different directory than is specified. I followed these steps:
- open intelliJ, click help -> show log in explorer
- modify build-log/build-log.xml and change
<priority value="info" />
to<priority value="debug" />
, you may have to run the editor as an administrator - run the compilation which fails with «Error:java: Fatal Error: Unable to find…»
- open build-log/build.log and search for rt.jar, you should find it in a block with a set of other JRE libraries and the directory which points to the file should be wrong
In my case the JDK is included in D:Developmentsoftwarejdk1.8.0_20, while the log points to C:UsersVladimirDevelopmentsoftwarejdk1.8.0_20
I fixed the issue by copying my JRE to the place which is expected in the log. And just like in your case this seems to only happen with JDK 1.8.
The problem comes from IntelliJ bug (existing at least in version 14).
It happens when your JDK directory is under the user profile directory. For example, JDK located in this directory (for Windows):
C:Usersmyuserjdk1.8.0_20
will be stored in IntelliJ internal configuration (file ‘jdk.table.xml’) as:
$USER_HOME$jdk1.8.0_20
But your %USER_PROFILE% environment variable could point at some other (non default) location. Then IntelliJ will look at the wrong directory.
Possible fix:
Install your JDK at different directory, which is outside your profile directory. Like:
C:Programsjdk1.8.0_20
Then register this JDK for use in your IntelliJ project settings.
I encountered this on Arch Linux 4.16.13 with IntelliJ 2018.1.4 after importing a Java project using Gradle. I made sure that there is a registered JDK in «Project Settings» -> «Project» but IntelliJ was unable to find the classes from the JDK, java.util.List
for example.
The solution was to add a new JDK entry at the same path as the existing JDK (/usr/lib/jvm/java-8-openjdk
in my case). This will cause IntelliJ to put the files under jre
onto the classpath whereas with the old JDK entry, only the files under lib
were on the classpath.
Had the same problem. Simple fix to others in case the other answers are complex.
Go to File -> Project Structure
Under Project SDK, choose new and add another JDK.
The default use in my case was 1.8 that was of build 181. I choose the 1.8.0_192 I had recently downloaded.
After applying, the project loads itself.
When I re-ran the test, it works!
If this problem occurs when importing a project in netbeans then try to create a new project then check the properties of your new created project and match those properties with the project that you imported in my case there was a difference between target of android package version.
From what I understood, debugging for hours, the problem is with the location where the jdk1.8 gets installed(/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home), instead of under System/Library).
So the following has to be done to fix in intellij
1. For an existing project, right click and select module settings, and SDK and add 1.8 as a version.
2. Using a terminal go to ~/Library/Preferences//options/. Remove the old JDK specific lines in jdk.table.xml. Update the default version in project.default.xml
Clean you project in intellij and build. It should use the new jdk and sync.