Receiving "wrong name" NoClassDefFoundError when executing a Java program from the command-line -
i have problem while trying executing java application. whenever try execute program through command
java progaudioj
i error:
exception in thread "main" java.lang.noclassdeffounderror: progaudioj (wrong name: es_2011/progaudioj) @ java.lang.classloader.defineclass1(nativemethod) @ java.lang.classloader.defineclasscond(classloader.java:632) @ java.lang.classloader.defineclass(classloader.java:616) @ java.security.secureclassloader.defineclass(secureclassloader.java:141) @ java.net.urlclassloader.defineclass(urlclassloader.java:283) @ java.net.urlclassloader.access$000(urlclassloader.java:58) @ java.net.urlclassloader$1.run(urlclassloader.java:197) @ java.security.accesscontroller.doprivileged(nativemethod) @ java.net.urlclassloader.findclass(urlclassloader.java:190) @ java.lang.classloader.loadclass(classloader.java:307) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:301) @ java.lang.classloader.loadclass(classloader.java:248) not find main class: progaudioj. program exit.
if remove code:
package es_2011;
everything works perfectly. how solve problem?
because found these answers unclear, here need do. first, if package code (ie classes have package
keyword @ top) compiled classes have in directory same name package declaration in code. after have compiled classes, need move directory when exectute java command, , include name of package. example, if code exists in /myfolder/mypackage/
, , class starts package mypackage
(note directory , package same name), following (linux / osx):
cd /myfolder/mypackage javac myclass.java cd .. java mypackage.myclass
edit - late edit clarify see people confused on. in example above, package 1 deep, meaning mypackage. if code has larger package, like
package com.somedomain.someproject;
you need execute java command directory contains root directory package. example if compiled code in mycode/com/somedomain/someproject/mymainclass.class, execute java command mycode folder, (again, take special note directory structure same package declaration):
cd /mycode java com.somedomain.someproject.mymainclass
Comments
Post a Comment