Do Java CLI commands work on Windows?

  • Thread starter Ramon F Herrera
  • Start date
R

Ramon F Herrera

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
 
L

Lew

Ramon said:
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 said:
-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:
 
T

Thomas Kellerer

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
 
R

Ramon F Herrera

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
 
R

Ramon F Herrera

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
 
A

Arne Vajhøj

Ramon said:
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
 
K

Knute Johnson

Lew said:
> From

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top