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:

  1. javac abmain.java
  2. mkdir sub
  3. set classpath=.:.\sub;
  4. move aaa.class .\sub\aaa.class
  5. move bbb.class .\sub\bbb.class
  6. 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):

  1. javac abmain.java
  2. mv aaa.class ./sub/aaa.class
  3. mv bbb.class ./sub/bbb.class
  4. java -cp ./sub:. abmain

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -