Vscode-java: pckage * does not exist, even though I can click through the class and get it to open in the editor

Created on 7 Mar 2017  路  4Comments  路  Source: redhat-developer/vscode-java

I'm just trying out visual studio code with the red hat java server with a rather large self-contained maven project.

I am getting a lot of package does not exist errors, even though they are clearly defined as dependency artifacts in the pom.xml. I also can click on the actual imported class and get vs code to open the class for viewing.

Eg. I get

file: 'file:///Users/tor/java/src/karriere/frontend/src/main/java/no/karriere/admin/controller/AdminController.java'
severity: 'Error'
message: 'package javax.servlet does not exist'
at: '20,21'
source: 'javac'

I'm suspecting some errors are happening somewhere that I cannot see in the vs code interface? Any idea on how I can go about to try to resolve this?

question

Most helpful comment

I tried removing the java linter extension, and the error wen away. Sorry for the interruption! I'll close this issue.

All 4 comments

This does not look like a message from vscode-java. Do you have any other java extensions installed?

I tried removing the java linter extension, and the error wen away. Sorry for the interruption! I'll close this issue.

I am having this problem and it is not related to the Java linter. External dependencies can be selected and I'll be taken to the source file, but when I launch the packages 'do not exist'. I'm also using the java debugger extension and have tried both with and without the gradle extension.

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Java",
      "type": "java",
      "request": "launch",
      "stopOnEntry": true,
      "preLaunchTask": "build", // Runs the task created above before running this configuration
      "jdkPath": "${config:java.home}/bin", // You need to set JAVA_HOME enviroment variable
      "cwd": "${workspaceRoot}",
      "startupClass": "project.webserver.ServerLauncher", // The class you want to run
      "sourcePath": [
        "${workspaceRoot}/src"
      ], // Indicates where your source (.java) files are
      "classpath": [
        "${workspaceRoot}/bin"
      ], // Indicates the location of your .class files
      "options": [], // Additional options to pass to the java executable
      "args": [] // Command line arguments to pass to the startup class
    }
  ]
}

tasks.json

{
    "version": "0.1.0",
    "command": "javac",
    "isShellCommand": true,
    "showOutput": "always",
    "isBackground": true,
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "build",
            "args": ["-g", "${file}"]
        }
    ]
}

I had the same issue. Turned out it was because I was using the extension Code Runner and ran with the default command:
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",

The solution for me is to install the Maven for Java, then run with it.

I have the following setting in Setting (JSON):

  "maven.terminal.favorites": [
    {
      "alias": "compile and run Main",
      "command": "exec:java -Dexec.mainClass=\"proj.Main\""
    }
  ],
  1. Bring up Command Palette (Ctrl+Shift+P)
  2. Type Maven: Execute Commands
  3. Choose project, then favorite, then the above command

Or if you prefer to use Code Runner (need Maven installed)
"java": "cd $workspaceRoot && cd proj-java/prac/ && mvn compile -q exec:java -Dexec.mainClass=\"proj.Main\""

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sfariaNG picture sfariaNG  路  3Comments

jnesspro picture jnesspro  路  4Comments

protoEvangelion picture protoEvangelion  路  3Comments

jcjolley picture jcjolley  路  3Comments

ViniciusAtaide picture ViniciusAtaide  路  4Comments