Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Do Java CLI commands work on Windows?

Thread view: 
Ramon F Herrera - 09 Dec 2007 22:44 GMT
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
Lew - 09 Dec 2007 22:52 GMT
> I always do most of my development inside an IDE (Eclipse or NetBeans)
> but lately I have been experimenting with the "Command Prompt" on
[quoted text clipped - 3 lines]
> 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.

Signature

Lew

Ramon F Herrera - 09 Dec 2007 23:02 GMT
> > I always do most of my development inside an IDE (Eclipse or NetBeans)
> > but lately I have been experimenting with the "Command Prompt" on
[quoted text clipped - 5 lines]
>
> 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
Ramon F Herrera - 09 Dec 2007 23:09 GMT
> > > I always do most of my development inside an IDE (Eclipse or NetBeans)
> > > but lately I have been experimenting with the "Command Prompt" on
[quoted text clipped - 24 lines]
>
> 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
Arne Vajhøj - 09 Dec 2007 23:20 GMT
> ps: this is what Wikipedia says:
>
[quoted text clipped - 7 lines]
>
> 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
Knute Johnson - 10 Dec 2007 02:39 GMT
 >  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
[quoted text clipped - 3 lines]
>
> 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

Signature

Knute Johnson
email s/nospam/knute/

Thomas Kellerer - 09 Dec 2007 22:54 GMT
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
[quoted text clipped - 9 lines]
>
> 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
Roedy Green - 10 Dec 2007 11:41 GMT
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
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.