just need sum help for classpath settings for command line compiling of classes of new java packages. i've been trying to do it but it only works for one package.

Follow these steps:

package mylib;

class First{
   public static void main(String []args) {
     System.out.println("First");
   }
}
public class Sample{
   public static void main(String []args){
     System.out.println("Sample");
   }
}

Now, compile the Sample.java file with following command line options;
(javac SourceFile.java –d [directoryname-where –you-want-to-create-package])
>javac Sample.java –d .
Now, execute the java bytescode using following command line
>java mylib.First
>java mylib.Sample

Another Sample:
Access the public classes of packages

Step-1. Create Sample.java file at c:\test1 folder and compile it

package mylib;
public class Sample{
  public Sample(){
   System.out.println("Sample from mylib");
  }
}

Step-2 Create Example.java file at c:\test2 folder and compile it.

package yourlib;
public class Example{
   public Example() {
     System.out.println("Example");
   }
}

Step-3. Create another .java file through which you want to access the classes of two packages.

public class TwoPackage{
   public static void main(String []args) {
       mylib.Sample a=new mylib.Sample();
       yourlib.Example b=new yourlib.Example();
   }
}

OR

import mylib.Sample;     
import yourlib.Example;  

public class TwoPackage{
   public static void main(String []args) {
       Sample a=new Sample();
       Example b=new Example();
   }
}

To compile TwoPackage.java file,
>javac TwoPackage.java –cp .;”%classpath%”;c:\test1;c:\test2;
To Execute bytescode,
>java –cp .;”%classpath%”;c:\test1;c:\test2; TwoPackage

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.