0

I wrote a simple java program

package abc.def.ghi 
public class Foobar{


   public String printS(String s){
     System.Out.println(s);

 public static void main(String [] args){
   String s = args[0];
   Foobar foobar = new Foobar();
    foobar.printS(s);
}

Now I did javac Foobar.java

It created a class file

and then I did

java Foobar

Didnt worked

 java Foobar hi //args

Didnt worked

java -cp . abc.def.ghi.Main

DIdnt worked.

Error I am getting is:

Exception in thread "main" java.lang.NoClassDefFoundError: abc/def/ghi/Main
Caused by: java.lang.ClassNotFoundException: com.intel.hadoop.graphbuilder.conf.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.intel.hadoop.graphbuilder.conf.Main.  Program will exit.
2
  • java -cp . abc.def.ghi.Foobar hi Commented Jan 3, 2013 at 23:09
  • 3
    Your problem has nothing to do with passing command line parameters. You have a classpath / package name issue Commented Jan 3, 2013 at 23:09

2 Answers 2

3

Did you put your .class files in the path (path to project)/abc/def/ghi/Foobar.class?

NoClassDefFoundError: abc/def/ghi/Foobar

Looks like you didn't.

Sign up to request clarification or add additional context in comments.

3 Comments

@Fraz Move Main.class files to (path to project)/abc/def/ghi/Main.class perhaps?
It would be Foobar.class, not Main.class.
@iamnotmaynard Oh, right. (reminds self to read question better)
1

If you compile using

javac -d . Foobar.java

then the compiler will put the .class file in the right directory to match its package name, then

java abc.def.ghi.Foobar

should run it successfully.

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.