Do Java CLI commands work on Windows? - Java

This is a discussion on Do Java CLI commands work on Windows? - Java ; I always do most of my development inside an IDE (Eclipse or NetBeans) but lately I have been experimenting with the "Command Prompt" on WinXP. I am under the impression -which I would obviously like to corroborate- that commands such ...

+ Reply to Thread
Results 1 to 8 of 8

Do Java CLI commands work on Windows?

  1. Default Do Java CLI commands work on Windows?


    I always do most of my development inside an IDE (Eclipse or NetBeans)
    but lately I have been experimenting with the "Command Prompt" on
    WinXP. I am under the impression -which I would obviously like to
    corroborate- that commands such these don't work at all:

    C:\> set CLASSPATH=C:\somedir\mylib.jar
    C:\> java -jar myprogram.jar

    or

    C:\> java -classpath C:\somedir\mylib.jar -jar myprogram.jar

    Should this one work at all?

    C:\> java -DMain-Class=playground.Salutations -jar helloworld.jar

    I have had very little success settings things up from the command
    line, but all my tests run well when I place things (Main-Class and
    Class-Path) in the Manifest.

    How is the verbose mode used? Is there any way to obtain essential
    info such as the Main Class and the classpath?

    TIA,

    -Ramon


  2. Default Re: Do Java CLI commands work on Windows?

    Ramon F Herrera wrote:
    > I always do most of my development inside an IDE (Eclipse or NetBeans)
    > but lately I have been experimenting with the "Command Prompt" on
    > WinXP. I am under the impression -which I would obviously like to
    > corroborate- that commands such these don't work at all:
    >
    > C:\> set CLASSPATH=C:\somedir\mylib.jar
    > C:\> java -jar myprogram.jar


    CLASSPATH will be ignored here.

    > or
    >
    > C:\> java -classpath C:\somedir\mylib.jar -jar myprogram.jar
    >
    > Should this one work at all?


    No, in the sense that the -classpath option will be ignored.

    > C:\> java -DMain-Class=playground.Salutations -jar helloworld.jar


    Main-Class isn't a command-line property.

    > I have had very little success settings things up from the command
    > line, but all my tests run well when I place things (Main-Class and
    > Class-Path) in the Manifest.


    Which is the documented behavior.

    > How is the verbose mode used? Is there any way to obtain essential
    > info such as the Main Class and the classpath?


    Yes, look at the manifest of the JAR. I don't know how "verbose mode" affects
    visibility of these parameters.

    From <http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html>
    > -jar
    > Execute a program encapsulated in a JAR file.
    > The first argument is the name of a JAR file instead of a startup class name.
    > In order for this option to work, the manifest of the JAR file must contain
    > a line of the form Main-Class: classname.


    Note the word "must" here.

    Continuing:
    > When you use this option, the JAR file is the source of all user classes,
    > and other user class path settings are ignored.


    --
    Lew

  3. Default Re: Do Java CLI commands work on Windows?

    Ramon F Herrera wrote on 09.12.2007 23:44:
    > I always do most of my development inside an IDE (Eclipse or NetBeans)
    > but lately I have been experimenting with the "Command Prompt" on
    > WinXP. I am under the impression -which I would obviously like to
    > corroborate- that commands such these don't work at all:
    >
    > C:\> set CLASSPATH=C:\somedir\mylib.jar
    > C:\> java -jar myprogram.jar
    >
    > or
    >
    > C:\> java -classpath C:\somedir\mylib.jar -jar myprogram.jar
    >
    > Should this one work at all?

    No, it should not.
    Read the manual for the java command.

    Quote from <http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html>:

    "When you use this option, the JAR file is the source of all user classes, and
    other user class path settings are ignored."

    Thomas

  4. Default Re: Do Java CLI commands work on Windows?

    On Dec 9, 6:52 pm, Lew <l...@lewscanon.com> wrote:
    > Ramon F Herrera wrote:
    > > I always do most of my development inside an IDE (Eclipse or NetBeans)
    > > but lately I have been experimenting with the "Command Prompt" on
    > > WinXP. I am under the impression -which I would obviously like to
    > > corroborate- that commands such these don't work at all:

    >
    > > C:\> set CLASSPATH=C:\somedir\mylib.jar
    > > C:\> java -jar myprogram.jar

    >
    > CLASSPATH will be ignored here.
    >


    My Linux server is running and ancient, non-Sun version of Java, hence
    my follow up question:

    Will the above work under Un*x?

    -Ramon

    ps: this is what Wikipedia says:

    "Setting the path through an environment variable.
    The Environment variable named CLASSPATH may be alternatively used to
    set the Classpath. For the above example, we could also use on
    Windows :

    set CLASSPATH=D:\myprogram
    java org.mypackage.HelloWorld"

    http://en.wikipedia.org/wiki/Classpath


  5. Default Re: Do Java CLI commands work on Windows?

    On Dec 9, 7:02 pm, Ramon F Herrera <ra...@conexus.net> wrote:
    > On Dec 9, 6:52 pm, Lew <l...@lewscanon.com> wrote:
    >
    > > Ramon F Herrera wrote:
    > > > I always do most of my development inside an IDE (Eclipse or NetBeans)
    > > > but lately I have been experimenting with the "Command Prompt" on
    > > > WinXP. I am under the impression -which I would obviously like to
    > > > corroborate- that commands such these don't work at all:

    >
    > > > C:\> set CLASSPATH=C:\somedir\mylib.jar
    > > > C:\> java -jar myprogram.jar

    >
    > > CLASSPATH will be ignored here.

    >
    > My Linux server is running and ancient, non-Sun version of Java, hence
    > my follow up question:
    >
    > Will the above work under Un*x?
    >
    > -Ramon
    >
    > ps: this is what Wikipedia says:
    >
    > "Setting the path through an environment variable.
    > The Environment variable named CLASSPATH may be alternatively used to
    > set the Classpath. For the above example, we could also use on
    > Windows :
    >
    > set CLASSPATH=D:\myprogram
    > java org.mypackage.HelloWorld"
    >
    > http://en.wikipedia.org/wiki/Classpath


    Now that I have read the 'man' page (RTFMP!) I guess my question is
    answered.

    I guess the designers are so eager to improve the loading time that
    they don't bother doing much error checking. For instance, the
    Manifest can be syntactically bad, and the user will not be told...

    -Ramon


  6. Default Re: Do Java CLI commands work on Windows?

    Ramon F Herrera wrote:
    > ps: this is what Wikipedia says:
    >
    > "Setting the path through an environment variable.
    > The Environment variable named CLASSPATH may be alternatively used to
    > set the Classpath. For the above example, we could also use on
    > Windows :
    >
    > set CLASSPATH=D:\myprogram
    > java org.mypackage.HelloWorld"
    >
    > http://en.wikipedia.org/wiki/Classpath


    The critical point is that the use of -jar changes
    some things.

    Including CLASSPATH and -classpath.

    And that is to my best of knowledge exactly the
    same on Linux/Unix and Windows.

    Arne

  7. Default Re: Do Java CLI commands work on Windows?

    Lew wrote:
    > From

    <http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html>
    >> -jar
    >> Execute a program encapsulated in a JAR file. The first argument is
    >> the name of a JAR file instead of a startup class name. In order for
    >> this option to work, the manifest of the JAR file must contain a line
    >> of the form Main-Class: classname.

    >
    > Note the word "must" here.


    A jar file created with the e option can use that classname as the entry
    point and no explicit manifest is required. On the other hand, a jar
    file can contain multiple classes and one can execute a specific class
    by specifying the jar file as the classpath and the name of the class
    one wishes to execute.

    java -cp TheJar.jar TheClass

    --

    Knute Johnson
    email s/nospam/knute/

  8. Default Re: Do Java CLI commands work on Windows?

    On Sun, 9 Dec 2007 14:44:12 -0800 (PST), Ramon F Herrera
    <ramon@conexus.net> wrote, quoted or indirectly quoted someone who
    said :

    >
    >C:\> java -classpath C:\somedir\mylib.jar -jar myprogram.jar


    I think most of your questions will be answered at
    http://mindprod.com/jgloss/javaexe.html
    http://mindprod.com/jgloss/classpath.html
    http://mindprod.com/jgloss/jar.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com

+ Reply to Thread

Similar Threads

  1. Constructing commands for [exec] under Windows
    By Application Development in forum TCL
    Replies: 2
    Last Post: 10-23-2007, 08:23 AM
  2. Re: Key commands do not work in illustrator CS
    By Application Development in forum Adobe illustrator
    Replies: 1
    Last Post: 11-20-2006, 02:25 AM
  3. Re: CS2 Keyboard commands do not worK?
    By Application Development in forum Adobe illustrator
    Replies: 0
    Last Post: 10-06-2006, 01:19 PM
  4. CS2 Keyboard commands do not worK?
    By Application Development in forum Adobe illustrator
    Replies: 0
    Last Post: 10-06-2006, 01:00 PM
  5. Re: Key commands do not work in illustrator CS
    By Application Development in forum Adobe illustrator
    Replies: 0
    Last Post: 09-29-2006, 04:07 AM