0

I have two classes Pair.java and Users.java where Users.java has the main program. Both these java files are under the package userdetails.

In unix, I compiled it using the command

javac -d . -classpath avro-1.7.5.jar:lib/*:jackson-core-asl-1.9.13.jar:lib/* Pair.java Users.java

the class are under the folder userdetails. I tried to run using the command

java  -classpath avro-1.7.5.jar:lib/*:jackson-core-asl-1.9.13.jar:lib/* userdetails.Users

I'm getting error

Could not find main class userdetails.Users

Kindly help me.

source code :-

import java.io.File; 
import java.io.IOException; 
import org.apache.avro.file.DataFileReader; 
import org.apache.avro.file.DataFileWriter; 
import org.apache.avro.io.DatumReader; 
import org.apache.avro.io.DatumWriter; 
import org.apache.avro.specific.SpecificDatumReader; 
import org.apache.avro.specific.SpecificDatumWriter; 
import org.apache.avro.util.Utf8;
public class Users {
 public void createUser() {
            userdetails.Pair datum = new userdetails.Pair(new Utf8("L"), new Utf8("R"));
            DatumWriter writer = new SpecificDatumWriter();
            DataFileWriter fileWriter = new DataFileWriter(writer);



            try {
                    fileWriter.create(datum.getSchema(), new File("users.avro"));
                    fileWriter.append(datum);
                    System.out.println(datum);
                    fileWriter.close();
            } catch (Exception e) {
                    // TODO Auto-generated catch block
                    System.out.println("ERROR");
                    e.printStackTrace();
            }         }

    public static void main(String[] args) {
            Users user = new Users();
            user.createUser();
    }
}
user2401464
  • 517
  • 2
  • 8
  • 20

2 Answers2

2

When you specify a classpath, the current working directory is not automatically contained any more, so you must add it to the classpath:

java  -classpath avro-1.7.5.jar:lib/*:jackson-core-asl-1.9.13.jar:lib/*:. userdetails.Users
isnot2bad
  • 24,105
  • 2
  • 29
  • 50
0

You say both classes are under the package "userdetails", but there is no package declaration at the beginning of your source. Both Pair.java and User.java should begin with the line:

package userdetails;

Check out the Java Packages Tutorial

vangelion
  • 255
  • 2
  • 7