The following program is throwing error:
public class HelloWorld {
public static void main(String args[]) {
System.out.println(\"Hello World!\");
Had the same problem tried above solutions but none worked. I had to go through my java code only to find that the main function could not be recognised since there was no space btw it and (String) ie initial code:
public static void main(String[]args){
working code.
public static void main (String[]args){
Hope I helped someone.
You can find information about required libraries inside pom.xml
, it is much easier to use tools like Apache Maven to build java applications.
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.20</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>4.2.0</version>
</dependency>
The CLASSPATH
variable needs to include the directory where your Java programs .class file is. You can include '.' in CLASSPATH
to indicate that the current directory should be included.
set CLASSPATH=%CLASSPATH%;.
If your package is helloworld
you would go to parent dir of your package then run:
java helloworld.HelloWorld
Here is what finally worked.
`@echo off
set path=%path%;C:\Program Files\Java\jdk1.7.0_71\bin;
set classpath=C:\Program Files\Java\jdk1.7.0_71\lib;
cd <packageDirectoryName>
javac .\trainingPackage\HelloWorld.java
cd ..
java trainingPackage.HelloWorld
REM (Make sure you are on the parent directory of the PackageName and not inside the Packagedirectory when executing java).`
Your CLASSPATH
needs to know of the location of your HelloWorld
class also.
In simple terms you should append dot .
(means current directory) in the CLASSPATH
if you are running javac
and java
commands from DOS prompt.