java - How to set environment variable CLASSPATH and NoClassDefFoundError on LINUX -
i've been studying classpaths , came across question. used code below:
class aaa { public aaa() { system.out.println("aaa"); } } class bbb { public bbb() { system.out.println("bbb"); } } class abmain { public static void main(string[] args) { aaa aaa=new aaa(); bbb bbb=new bbb(); } }
on terminal, did:
- javac abmain.java
- mkdir sub
- set classpath=.:.\sub;
- move aaa.class .\sub\aaa.class
- move bbb.class .\sub\bbb.class
- java abmain
when checked sub directory, found aaa.class , bbb.class correctly moved, when try run abmain, following:
exception in thread "main" java.lang.noclassdeffounderror: aaa @ abmain.main(abmain.java:17) caused by: java.lang.classnotfoundexception: aaa @ java.net.urlclassloader.findclass(urlclassloader.java:381) @ java.lang.classloader.loadclass(classloader.java:424) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:335) @ java.lang.classloader.loadclass(classloader.java:357) ... 1 more
could please comment on should change make work? thank in advance.
according title, use linux. steps windows ecosystem. correct example, should use direct slash path delimiter, , add current dir classpath alternative (to able load main class well):
javac abmain.java
mv aaa.class ./sub/aaa.class
mv bbb.class ./sub/bbb.class
java -cp ./sub:. abmain
Comments
Post a Comment