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();
    }
}
7
  • 1
    post some code here specially your main method Commented Nov 14, 2013 at 10:00
  • 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 static void main(String[] args) { Users user = new Users(); user.createUser(); } } Commented Nov 14, 2013 at 10:04
  • 1
    now please edit your question and put the remaining part of your code there Commented Nov 14, 2013 at 10:06
  • 1
    Your code doesnt have a package statement at the top Commented Nov 14, 2013 at 10:10
  • added and ran it .. still the same issue Commented Nov 14, 2013 at 10:12

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.