1

I am trying to run my netbeanz project from command line , it works when I run it from the netbean IDE

I have already read this and this and the sun java tutorial but I am still unable to solve the problem.

My main file : hill.java is located in the following folder

enter image description here

In command line , I change directory to the above and run javac *.java which works as expected

enter image description here

The problem arises when I attempt to java hill ( hill.java is the name of my main class file )

enter image description here

Contents of directory hill

enter image description here

hill.java

package hill;


import java.util.Random;
import java.io.*;
import java.util.*;
import java.math.*;

public class Hill 
{

   public static void printmenu()
{
    printline();
    System.out.println("Welcome to Hill Cipher");
    System.out.println("1) Key Generation");
    System.out.println("2) Encrypt");
    System.out.println("3) Decrypt");
    System.out.println("4) Quit");
    printline();
}

    public static String readString(String prompt) 
{
System.out.print(prompt);
return new java.util.Scanner(System.in).nextLine();
}

public static int readInt(String prompt) 
{
int input = 0;
boolean valid = false;
while (!valid) {
  try {
    input = Integer.parseInt(readString(prompt));
    valid = true;
  } catch (NumberFormatException e) {
    System.out.println("*** Please enter an integer ***");
  }
}
return input;
}


    public static void main(String[] args) 
    {


        int choice=0;
        do 
        {
            printmenu();
            choice = readInt("Please select your option : ");
            selectmenu(choice);

        }while (choice != 4);

    }

}

What am I doing wrongly and how do I solve this problem ??

Community
  • 1
  • 1
Computernerd
  • 7,378
  • 18
  • 66
  • 95

2 Answers2

1

Two things.

  • Execute "java hill.Hill" from your src folder, not the hill folder since you are using a package.
  • Capitalize hill for the class so it reads "java hill.Hill"

Good luck.

AtlasMeh-ed
  • 469
  • 5
  • 7
  • 1
    The `java` command expects a fully qualified class name. Note that packages contain `.`s, not `/`s like the corresponding folder hierarchy does. This means that `java hill.Hill` is correct. – Code-Apprentice Oct 25 '14 at 01:50
  • Yep you're right. I edited my answer to reflect that. The command is lenient however and it still runs although not correct with "/". – AtlasMeh-ed Oct 25 '14 at 01:55
0

you can also use this way:

java -jar "C:\Users\8382c\Documents\NetbeansProjects\Hill\dist\hill.jar"