Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10324

Re: Java classpath question and how to run a program from command line?

From www <xsli2@yahoo.com>
Newsgroups comp.lang.java.programmer
Subject Re: Java classpath question and how to run a program from command line?
Date 2011-11-29 06:14 -0800
Organization http://groups.google.com
Message-ID <ed80ba1f-864b-4fda-b619-abcd90f6ce2c@gl2g2000vbb.googlegroups.com> (permalink)
References <85f06dad-9e66-42ef-a232-d98c72832318@cc2g2000vbb.googlegroups.com>

Show all headers | View raw


On Nov 28, 4:50 pm, www <xs...@yahoo.com> wrote:

>
> Now in Cygwin command window, I am at /cygdrive/d/project/bin, I typed
> the command below, but it didn't work:
>
> java -classpath /cygdrive/d/project/libs;. A.B.C.MainWindow
>
The output from the failing command above is showing the following
only:
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -client       to select the "client" VM
    -server       to select the "server" VM
...
[truncated]

Now, I can make it work:

java -classpath "/cygdrive/d/project/libs/*;." A.B.C.MainWindow

by adding the pair of " on the parameter after -classpath AND libs/*,
not libs only. Both corrections are needed to make it work.

Now, I still have another puzzle: I want to set CLASSPATH beforehand,
so I don't need to type "-classpath xxxx". In .bashrc file, I have:
export CLASSPATH="/cygdrive/d/project/libs/*;/cygdrive/d/project/bin"

run ". .bashrc", no complains. If I understand package concept
correctly, now, no matter which directory I am, I can type this
command:

java A.B.C.MainWindow

To my surprise, it says:
Error: Could not find or load main class A.B.C.MainWindow

I don't get it. Since CLASSPATH points to /cygdrive/d/project/bin
already, searching A.B.C.MainWindow should find /cygdrive/d/project/
bin/
A/B/C/MainWindow.class. Why it cannot find it?

Thank you again for all your help.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Java classpath question and how to run a program from command line? www <xsli2@yahoo.com> - 2011-11-28 13:50 -0800
  Re: Java classpath question and how to run a program from command line? Robert Klemme <shortcutter@googlemail.com> - 2011-11-28 23:08 +0100
  Re: Java classpath question and how to run a program from command line? markspace <-@.> - 2011-11-28 14:21 -0800
  Re: Java classpath question and how to run a program from command line? Lew <lewbloch@gmail.com> - 2011-11-28 15:58 -0800
  Re: Java classpath question and how to run a program from command line? www <xsli2@yahoo.com> - 2011-11-29 06:14 -0800
    Re: Java classpath question and how to run a program from command line? www <xsli2@yahoo.com> - 2011-11-29 06:54 -0800
      Re: Java classpath question and how to run a program from command line? Lew <lewbloch@gmail.com> - 2011-11-29 07:43 -0800
        Re: Java classpath question and how to run a program from command line? www <xsli2@yahoo.com> - 2011-11-29 09:22 -0800
          Re: Java classpath question and how to run a program from command line? Lew <lewbloch@gmail.com> - 2011-11-29 12:08 -0800
  Re: Java classpath question and how to run a program from command line? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-29 13:57 -0800

csiph-web