Vs Code java The import cannot be resolved - java

I recently moved from windows 10 to Ubuntu 16.04, I'm a java developer, when I was on windows I installed Vs Code with the java Extension pack. On windows I never Had problem to make my daily work, but on ubuntu, every java file is marked as error, with the message "The import cannot be resolved", searching a litle bit, i found that you can execute the command java:clean the java language server workspace, but this does not fix the problem. I also remove the tmp files from the workspace located on:
~/.config/Code/User/workspaceStorage
the current Version of Vs code is 1.41.1
the current version of Java Extension Pack is 0.8.1
Any ideas?.
Regards!.
Edit:
all my java files are marked as error
inside of every java file
this is the result of the maven-install

well, after a while of searching, I found that the "maven for java" plugin was trying to download the maven plugin maven-metadata.xml, which wasn't available on my repo. this caused a conflict with the initial build that maven for java was doing. to avoid to update every time I opened vs code, I removed the option "update snapshots"
And the initial build was done.

Related

projects with jaxb in netbreans are throwing an error if netbeans is executed with graalvm 22+

Today i've upgraded my local jdk from graalvm-ce-java17-22.2.0 to graalvm-ce-java19-22.3.0 because the runtime crashed a few times in my debug sessions.
Then i wanted to run my netbeans project, which failed with the following error message:
Error: Could not find or load main class FQN-OF-MAIN-CLASS in module jdk.internal.vm.compiler
C:\...\nbproject\build-impl.xml:1418: The following error occurred while executing this line:
C:\...\nbproject\build-impl.xml:924: The following error occurred while executing this line:
C:\...\nbproject\build-impl.xml:943: Java returned: 1
BUILD FAILED (total time: 2 seconds)
Because the project was running before the upgrade, I've closed netbeans, deleted the netbeans-cache, updated the environment variables to point to the new jdk (wasnt neccessary before), changed netbeans conf so that netbeans is running with the new jdk too and started netbeans again.
same error. creating another runable class in this project or executing a single class instead of the hole project results in the same error too. creating a new project running a hello-world-file succeeds. also, in the "problematic" project, if i hit clean-and-build and run the resulting jar from command line thats works well, but netbeans seems to have a problem debugging/running the project from within the ide. also restored nbproject/build-impl.xml and nbproject/project.xml from repository, but still getting the same error. also tried going back to v22.2 but now i get the same error there too.
So I assume that I messed it up somewhere, but don't know where I should start looking? The error points to the ide generated ant script which i havent touched, older projects and newly created projects are running fine...
any ideas?
netbeans 15
windows 10 22H2 x64
graalvm-ce-java19-22.3.0
EDIT 1:
It does not seem related to source code. removed every file from /src and created a new class test/NewClass.java with a main that also produces the error.
EDIT 2:
Tried graalvm-ce-java17-22.3.0, but got the same error.
EDIT 3:
Could track it down (a bit), it's somehow related to JAXB bindings. Creating a new project, changing Platform to 1.8 with StandardJDK, adding a JAXB-Binding and running an empty main class works. Changing the Platform to 16/17/19 with GraalVM produces the error. Reverting back to 1.8. resolves the error. Of course the problematic project makes use of JAXB, but its running with GraalVM 16/17 for quite some time without producing the error. Fun fact, netbeans is adding a JAXB version 2.3.5 which seems not public availiable on the maven repository.
EDIT 4:
JAXB itself seems to be not the primary problem, but its related. If netbeans is executed with the standard JDK 1.8 or GraalVM 21.1 JAXB works in all kind of projects, regardless of the platform the project is executed with.
But if I change the JDK netbeans is started with to GraalVM 22 or newer, then projects containg JAXB are producing the above error.
Since JAXB in Netbeans 15 works with GraalVM 21 but not newer versions I think that probably be a problem with GraalVM rather than netbeans.
Does Netbeans support JDK19? You might want to try graalvm-ce-java17-22.3.0, i.e. upgrade GraalVM version but stay on the JDK17 line

Building with Gradle - Supplied javaHome must be a valid directory

I am having a lot of trouble for what should be an easy task. I'm trying to build a simple Java project (just Hello World) with Gradle for one of my courses before classes begin. I cloned the repository, downloaded all the relevant software, and tried gradle build on the command line. I get the error Supplied javaHome must be a valid directory. You supplied: C:\Program Files\AdoptOpenJDK\jre-8.0.282.8-hotspot. This file that shows up was a previous version that I had removed.
I tried reinstalling everything, and I also checked the JAVA_HOME environment variable, which is set to C:\Program Files\AdoptOpenJDK\jdk-15.0.2.7-hotspot\. I've also relaunched the terminal and rebooted my computer. I'm using Git Bash as my shell, if that's anything relevant. Any advice on how to change the supplied javaHome?
Here are some relevant screenshots:
Result of gradle build
Result of java -version
JAVA_HOME environment variable
My (very sketchy) solution is to make a copy of the existing jre15 folder I have and rename it to jre-8.0.282.8-hotspot. I can build and run my program now, but it just seems very sketch.
One year update: I asked my prof when classes started when he said this solution was actually pretty ok and would suffice for the semester.
I had a similar problem building a Java app on GitHub Actions. Once I upgraded from Java 11 to Java 16 I started to get the same error as you.
In my case it turned out to be a caching problem. I was caching two directories:
~/.gradle (on windows this should be something like C:\Users\username\.gradle)
project/.gradle (this one is the gradle directory that is local to my app project).
Invalidating the caches fixed the issue for me.
I had a similar problem after uninstalling a Java version with Gradle deamon running. Stopping the deamon fixed the issue for me:
gradle --stop
(Probably, a cross-platform equivalent of Miguel's solution)
Update gradle(gradle-wrapper.properties) version from Android Studio to the lates version
For me i just deleted the .gradle in my folder C:\Users\username\.gradle.
With Android Studio, dependencies are automatically reinstalled

Unable to find package java.lang in classpath or bootclasspath with ant [duplicate]

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:
Restarted, reinstalled
Invalidate Caches / restarted
Deleted / readded the JDK in Project JDK
Deleted / readded the JDK in Platform Settings
Rebuild / recompile
In Windows I already:
Deleted / Reinstalled Java SDK
Deleted / Readded the JAVA_HOME, PATH and CLASSPATH on System Variables
Tried the above on User Variables
Deleted and reinstalled IntelliJ IDEA
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.
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:\Development\software\jdk1.8.0_20, while the log points to C:\Users\Vladimir\Development\software\jdk1.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:\Users\myuser\jdk1.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:\Programs\jdk1.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.

Correct Java dependencies installed for eclipse ADT development

I have eclipse and the ADT bundle correctly installed on my home PC, and tried to install it on my laptop so I can work on my projects on the go. However, I either didn't set the java paths correctly, or installed them in the wrong place, because I can't get a default project to load without errors.
I have correctly:
-Installed the ADT bundle and launched eclipse without errors
-Created a workspace
-Correctly Installed both the jre8 and jdk1.8.0_05 in the location C:\Program Files\Java
I am very new to Android development, and I feel like I was lucky to set up the Java dependencies correctly on my home PC, no such luck this time from what the error look like...
However, when I try to make a basic "Hello world" project, I immediately get the following error:
The container 'Android Dependencies' references non existing library 'C:\Users\userName\workspace\appcompat_v7_3\bin\appcompat_v7_3.jar'
I have tried adding the library, by checking build configurations, but I don't understand fully whats going on to correctly solve the problem. Here is my workspace:
And lastly, I tried checking the build configurations to see that the libraries are, in fact, missing. Or something like that. I am not sure if I should just try to reinstall java and the jdk.
Build configuration:
Anyway, I'm not sure what I deleted, misplaced, uninstalled, or didn't install, but if anyone could point me to a solution I would be very grateful. If anyone has any other questions on my setup I will try and be as thorough as possible. Thank you!
In my experience I have had issues like this if not running eclipse as Administrator. Make sure that you aren't being blocked here.
EDIT: Please note Chris Stratton's concers regarding running an IDE as Administrator, as seen in the comments below.
EDIT 2: In my more recent experience, I have noticed that if I installed the SDK by copying and pasting the contents of the downloaded, compressed, folder to a destination rather than extracting it first, I would be required to run as Administrator. If this is the case, delete the SDK that you copied out of the compressed folder and simply extract the contents of the downloaded compressed folder. I am running Windows 7 so it is likely that this applies to all Windows 7 and 8 OS's.
In another case, I have also seen issues like this if the JRE is installed second rather than first. In this case, a reinstall of the SDK is probably all that is required.

Thinking in java library installation

Hi i've been trying to install the library on Thinking in Java book 4th edition and i hit a very thick brick wall. I've done everything that the guide from the website told me to do and i still can't get the library to work. From what i've read it seems that the problem is from the build.xml files. having no xml knowledge I am clueless about how I have to modify it in order for it to work. In both cmd and eclipse I am getting these error
c:\TIJ4\code\build.xml
Build Failed
c:\TIJ4\code\build.xml:59:J2SE5 required
Can anyone tell me what I should do ?
I am using eclipse if there is a simpler solution by using eclipse rather than ant please help me out. It's been a week now and I still can't make it work.
The important thing to do is to realize that your ant file has a specific java requirement.
Something to try that might fix this very easily : I believe you can remove any references to a specific JDK, and if you have a reasonably up to date JDK, the build will succeed.
The definete fix : Look into the exact (line 59) of your build file, and try to satisfy the java version that line requires. Java is generally backwords compatible -- something designed to run in J2SE5 should run in the latest JDK. Its not terribly difficult to update your JDK (just google for instructions on your OS).
The most common mistake I see is that people who have the java run time installed believe they also have the Java SDK as well.
Does this "install the library" means you want to look at the code and run them in your eclipse? If so I can share my experience with you.
First run the Eclipse.py script; this will add package info to the source code
Create a new Java project in Eclipse, and then just copy all the source code folders to the src source folder in eclipse, these folders will then be recognized as Java packages.
You should be able to run the classes with a main function.
You can also configure which java version to use for this project in Eclipse build path. 1.5 or higher will work.

Categories