exception in thread 'main' java.lang.NoClassDefFoundError:

后端 未结 23 3349
心在旅途
心在旅途 2020-11-28 06:27

The following program is throwing error:

public class HelloWorld {
    public static void main(String args[]) {
        System.out.println(\"Hello World!\");         


        
相关标签:
23条回答
  • 2020-11-28 06:39

    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.

    0 讨论(0)
  • 2020-11-28 06:40

    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>
    
    0 讨论(0)
  • 2020-11-28 06:43

    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%;.
    
    0 讨论(0)
  • 2020-11-28 06:44

    If your package is helloworld you would go to parent dir of your package then run:

    java helloworld.HelloWorld
    
    0 讨论(0)
  • 2020-11-28 06:46

    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).`
    
    0 讨论(0)
  • 2020-11-28 06:46

    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.

    0 讨论(0)
提交回复
热议问题