running java from command line
java
Solution
You need to run the java command up one directory level and give it in the fully qualified package name, eg: `java main.Main`
See How the Java Launcher Finds User Classes to learn how this works.
Problem
I have been mostly using eclipse so far. Now I'm trying to run java from terminal but I have a problem with packages. This is my `Main.java` file: ``` package main; class Main { public static void main(String[] args) { System.out.println("it's working"); } } ``` I compile this using `javac Main.java` and then run with `java Main` which gives me: ``` java Main Exception in thread "main" java.lang.NoClassDefFoundError: Main Caused by: java.lang.ClassNotFoundException: Main at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: Main. Program will exit. ``` When I remove `package Main` everything works fine. What am I missing? `java -version` gives: ``` java version "1.6.0_24" OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1) OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode) ```