Compiling multiple packages using the command line in Java

后端 未结 6 1665
余生分开走
余生分开走 2020-11-30 08:05

Hi i have been using an IDE but now I need to run and compile from the command line.

The problem is that I have multiple packages and I have tried to find the answe

6条回答
  •  甜味超标
    2020-11-30 08:39

    The real answer is javac -d (places where classes to be built and placed) -sourcepath (source of the package at the root) -cp (classpath of the dependencies which can again be classes folder where the classes are build and kept) full qualified name of the java file.

    Ex javac -d classes -sourcepath src -cp classes src\com\test\FirstSample.java

    The FirstSample.java contains the main method. Pacjage structure mentioned below.

    Before compiling
    HomeApp
    --src
    ------com\test\FirstSample.java (First Sample using the FirstPojo.java)
    ------com\test\FirstPojo.java
    --classes

    After compiling
    HomeApp
    --src
    ------com\test\FirstSample.java (FirstSample.java using the FirstPojo.java)
    ------com\test\FirstPojo.java
    --classes
    ------com\test\FirstSample.class (FirstSample.class using the FirstPojo.class)
    ------com\test\FirstPojo.class

提交回复
热议问题