How do I compile and run java files if you don't know the specific package used by the developer...
I got a folder of java files written by someone else, and I'm trying to compile and run the java files, I can compile the files by running javac *.java, but if I try to run the main class by calling java MainClass, I get an error like so: Error could not find or load main class MainClass, Caused by: java.lang.NoClassDefFoundError: SomePackageName/MainClass (wrong name: MainClass)
I have no idea whats the SomePackageName its defined by the developer and I have no control over that.
so the question is how do I compile and run the java files if all I know is which is the main class?
com.foo.Bar, wherecom.foois the package (e.g. the file defining the Bar class starts with the linepackage com.foo;), and Bar is the name (e.g. the file contains the linepublic class Bar {).javaand specifying classpath+classname, you pass a class name. Not a file name. So to run this file you'd writejava -cp /path/to/base com.foo.Bar./Users/Foghunt/projects/myproj/src/com/foo/Bar.javaand after compilation you should have e.g./Users/Foghunt/projects/myproj/build/com/foo/Bar.class/Users/Foghunt/projects/myproj/srcand for the compiled result is/Users/Foghunt/projects/myproj/build.java -cp /Users/Foghunt/projects/myproj/build com.foo.Bar.javacdoesn't mind if you don't go through the trouble of properly defining things (e.g. runningjavac *.javain/Users/Foghunt/projects/myproj/src/com/foodoes work), but it gets complicated quickly if you have multiple packages.build.xmlorpom.xmlorbuild.gradlein the root of the project. If it is there, use a web search engine (build.xml-> search forjava ant,pom.xml->java maven,build.gradle->java gradle), and use that to build the project, don't runjavacyourself.There you go. Armed with that knowledge you can now analyse, build, and run any java project.