-1

I built a little command line program in java. It has a class that gets instantiated and used in the main method. But when I go to compile it at the command line it doesn't 'see' the class it needs to run. It accepts arguments passed in at runtime. I can set it up in Netbeans and it runs beautifully. But I want to be able to use it at the command line. I've tried jar-ing it up, it throws an exception and doesn't see the class that I'm instantiating in main. I took Java in my CS program, but my Prof didn't cover deployment in particular depth.

Any ideas to help me out of my pickle?

Thanks!!

  • You really haven't given much information for people to help you, I recommend posting the exception and trying to focus on your question on a specific issue. http://stackoverflow.com/faq#questions – James McMahon Feb 17 '13 at 01:14
  • The SO thread [How to create executable .jar file with netbeans](http://stackoverflow.com/questions/1946394/how-to-create-executable-jar-file-with-netbeans) is a good starting point for you, I think. – Perception Feb 17 '13 at 01:14
  • Here's part of the error. ception in thread "main" java.lang.NoClassDefFoundError: Age (wrong name: age/ e) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:791) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14 at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) – Osgaldor Jason Storm Feb 17 '13 at 01:48

1 Answers1

0

Do either of your classes have packages? If they do, they'll have a first statement of "package ", and it makes a difference.

I'm going to assume that at least your Age class does have a package, I'll call the package 'a'.

Let's further assume a main class of "Alex"; it would have an import statement of "import a.age;".

Let's assume you are in a directory named "george".

Your Alex.java file (without a package statement) needs to be in george. Age.java needs to be in a directory underneath george named a.

You can compile your main file with the command "javac Alex", and can run it with "java Alex".

If you tell us more specifics about your problem, we can be more specific about what you need.

arcy
  • 12,845
  • 12
  • 58
  • 103
  • When I created it in Netbeans, it got put in package called Age. The class that does the age calculation is called Anage and the class with the main function is in class Age. It works in netbeans, but I can't get it to work at the command line. – Osgaldor Jason Storm Feb 19 '13 at 23:11
  • So the main method class is Age and the specialized class is Anage and they are both in package age. – Osgaldor Jason Storm Feb 19 '13 at 23:13
  • I created a jar with a manifest identifying the main class and when I try to run it with java -jar age.jar I get this error: C:\jprac\age>java -jar age.jar Exception in thread "main" java.lang.NullPointerException at sun.launcher.LauncherHelper.getMainClassFromJar(LauncherHelper.java:3 99) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:463) – Osgaldor Jason Storm Feb 19 '13 at 23:28