I have a package with some classes inside D:\ProjectGsc\. The package root folder is called gsc and contains three subdirectories namely util,core and modules. Inside each of them are some files and inside core there is a file named gsc.class. Apart from those there is also a folder res inside the gsc folder that contains some images that are used by the JFrames and JDialogs inside my package’s classes. I manage to compile everything using -classpath \projectgsc and, as the code has been debugged, everything is compiled smoothly. But I cannot run it at all. I try to java gsc -classpath \projectgsc while I am inside D:\ProjetctGsc\gsc\core\ but it gives me exception in thread main (syntax of main is correct for sure) java.lang.NoClassDefFoundError: gsc (wrong name: gsc/core/gsc). Is it because of the name of my class being gsc inside package gsc.core?
Thanks in advance! (Btw SO does not allow me to name the question “Classpath problem when running” so this is the best title I could come up with, feel free to edit it)
Yes, to run a class called
gsc(which violates Java naming conventions, btw) in a packagegsc.core(ick – package name containing the class name; confusing!) you’d writeBut you’d have to compile it so that you had a directory structure of
You’ll get this automatically if you use the
-doption to javac:(Adjust accordingly, of course.)
You may well find that if you’re new to Java, using an IDE which handles all of this for you would make your life easier.