Reputation: 171
//Vector.java
package simple;
public class Vector{
public Vector(){
System.out.println("net.mindview.simple.Vector");
}
}
//List.java
package simple;
public class List{
public List() {
System.out.println("net.mindview.simple.List");
}
}
//LibTest.java
import simple.*;
public class LibTest{
public static void main(String[] args) {
Vector v = new Vector();
List l = new List();
}
}
When I try to set the classpath for Vector or List,
like
java classpath "C:\Learning Java\AccessControl" simple.Vector, I could Main method could not be found, please define main method. But in the book I'm using, neither file needs to have a main method.
If I try to run LibTest I get cannot access Vector and class file contains wrong class:Vector, errors.
Upvotes: 0
Views: 2102
Reputation: 1
To run package first you have to compile it from the directory
ex., C:\package-name\abc.java
package-name: as you mentioned simple.
After it you have to run "abc.java" file from the directory. ex., C:____
Hope it will work
Upvotes: 0
Reputation: 85779
From your posted code, nor Vector
or List
classes has the public static void main(String[] args)
method in it, thus you getting the error.
Note that LibTest
class has it, so it would be better to execute this class:
java classpath "C:\Learning Java\AccessControl" other.package.LibTest
Upvotes: 1