Re: Setup linux and java
If your class is "sampleTest" in a "mainPkg" package (which means sampleTest.java contains "package mainPkg;") after the compile you should end up with a file bin/mainPkg/sampleTest.class.
And to invoke it from the command line, the classpath should point to the "bin" directory and you designate the class as mainPkg.sampleTest, ie:
In other words:
java -cp bin mainPkg.sampleTest
- the class path items are the directories (or jar) just above the "root" packages
- class are designated by their full path, replacing directory separators by dots
- the package in the class should match its position
For instance if you have the following directory/file structure: a/b/c/d/e/Foo.class
- if Foo has no package then the classpath should include the directory a/b/c/d/e and the class is just "Foo"
- if Foo is declared in package "d.e" then the classpath should include the directory a/b/c and the class is d.e.Foo
Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.