Search code examples
javajavac

Error when try to run my project in cmd


I have a structure code like this :

enter image description here

I want to run my program using mcd using javac, like this : javac ListenerZipFile.java. The result like :

enter image description here

Why i can't run my program?


Solution

  • There are 2 problems here.

    1. Incorrect directory location for compiling packed classes.
    2. classpath no set correctly.

    Consider you have, source_dir = D:\~\~\src, jar_location = D:\~\~\lib and package is com.example then your steps to compile are:

    • cd to $source_dir
    • $source_dir> set classpath=.;jar_location
    • $source_dir> javac com\example\Examples1.java or $source_dir> javac com\example\*.java

    As per path shared, command to compile should be :

    cd C:\ListenerZipfile\src
    javac -cp .;C:\ListenerZipfile\lib\*.jar com\sigma\main\ListenerZipFile.java
    

    Command to run java program with above path:

    java -cp .;C:\ListenerZipfile\lib\*.jar com.sigma.main.ListenerZipFile