Hi guys! I have a webapp that runs on a tomcat container. I have a standalone application inside it in WEB-INF/classes/dir1/dir2/dir3. Why is it that when I go to WEB-INF/classes/dir1/dir2/dir3 and then invoke
That is because your class is in the package dir1.dir2.dir3.
When you run a Java program that is in a package, you must make sure that the base directory of the package is in the classpath, and you have to specify the fully-qualified class name (i.e. the class name including the package name) on the command line.
By default (if you don't specify a classpath) Java will use the current directory. So it works if you are in the directory WEB-INF/classes, because that is the base directory of the package.
You can try specifying the classpath on the command line explicitly, then it doesn't matter from which directory you start it:
With other words, the name of the class is dir1.dir2.dir3.MyClass. This is also the called the "fully qualified name" of the class.
You are allowed to use the shortened name (without the package prefix) in Java code when you use an import statement. The same is not possible with the java command when you want to run the class - there you always need to use the fully qualified name.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus