I have read the previously posted questions. Some are vague and none solved my problem so I am forced to ask again.
I have two simple classes,
package One; import One.Inner.MyFrame; public class test { public static void main(String args[]) { MyFrame f= new MyFrame(); } }
And the other class is,
package One.Inner; import java.awt.*; import javax.swing.*; public class MyFrame extends JFrame { public MyFrame() { setPreferredSize(new Dimension(400,560)); setVisible(true); } }
I am at base folder "basic" in Windows cmd. I compile using
basic> javac *.java -d .
A folder and subfolder is created.
cd One basic\One> java test
This generates a big set of errors. Many answers directed to specify the full path which didn't work. My classes are in One so specifying One using -cp didn't work either.
How to run java package program. You need to use fully qualified name e.g. mypack. Simple etc to run the class. The -d is a switch that tells the compiler where to put the class file i.e. it represents destination.
Open a command prompt and navigate to the compile-packages-in-java directory. Then type in the command to compile the Person source and hit Enter . Notice that you provided the path of the Java file. This path corresponds to the package name.
You'd run it as:
java One.Test
... but from the root directory (basic
), not from the One
directory. You always specify the fully-qualified class name.
Oh, and package names in Java should be lower-case, so it should be one
and one.inner
, not One
and One.Inner
. Just a convention, but one which pretty much everyone follows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With