As a first step, try to compile your programm from te command line. E.g. How do I run a Java program from the command line on Windows? is a good start. You can run the commands directly in VSCode's integrated terminal. Optionally, create a VS Code build task from that command to run builds with the build command.
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Foo",
"type": "shell",
"command": "javac foo.java",
"problemMatcher": []
}
]
}
To run/debug, create a launch config in the debug viewlet, for example:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-Foo",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "Foo",
"args": ""
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 0
}
]
}
Answer from Martin Aeschlimann on Stack OverflowHow to run java in VSCODE
How can I get JAVA to run in VS code??
Unable to run java project on vscode
How to run Java in VScode
Do I need to install a JDK to run Java in VS Code?
What extension do I need to run Java in VS Code?
How do I debug Java in VS Code?
As a first step, try to compile your programm from te command line. E.g. How do I run a Java program from the command line on Windows? is a good start. You can run the commands directly in VSCode's integrated terminal. Optionally, create a VS Code build task from that command to run builds with the build command.
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Foo",
"type": "shell",
"command": "javac foo.java",
"problemMatcher": []
}
]
}
To run/debug, create a launch config in the debug viewlet, for example:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-Foo",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "Foo",
"args": ""
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 0
}
]
}
If you are using Maven, you should see a MAVEN tab at the bottom of the left menu bar. Clicking on it will expand to show your project name. Right click on it shows a "Run Maven Commands" option, under which you will see Compile and other stuffs like run and debug.
Hi everyone,
I am a complete newbie to java and I'm getting overwhelmed with the barrier of entry to even start writing code. I have VSCode and have my java file, but I can't figure out how to run the code so I can see Hello World!
Here is the code:
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" in the terminal window.
System.out.println("Hello, World");
}
}
And here is the error message when I do java HelloWorld :
Error: Could not find or load main class HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
What do I do? I thought I downloaded all the right extensions and everything. Why can't I just write the code and click a button to run it?
Thank youI have downloaded the MS java package.
I have created a new java file (java extension)
I am creating a simple hello world print
public class testing 3
{
public static void main(String[] args)
{
System.out.println("hello world");
}
}I have tried Alt C, Alt R and F5 but I cannot see anything in the OUTPUT section of the terminal. I am probably missing something simple. There is a little JAVA symbol beside my file name so I know it is working in java. If there was an error in the code, I would have thought I could see that, but nothing.