Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java -cp . HelloWorldApp

0 views
Skip to first unread message

hawat....@gmail.com

unread,
Jun 20, 2006, 3:54:45 AM6/20/06
to
How do I execute HelloWorldApp, please?


Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>dir
Volume in drive C has no label.
Volume Serial Number is FCD2-42DE

Directory of C:\

11/21/2005 11:15p <DIR> Documents and Settings
06/19/2006 02:18a 266 HelloWorldApp.java
06/19/2006 02:14a <DIR> Program Files
06/19/2006 02:18a <DIR> WINNT
1 File(s) 266 bytes
3 Dir(s) 1,114,669,056 bytes free

C:\>javac HelloWorldApp.java

C:\>dir
Volume in drive C has no label.
Volume Serial Number is FCD2-42DE

Directory of C:\

11/21/2005 11:15p <DIR> Documents and Settings
06/19/2006 02:24a 432 HelloWorldApp.class
06/19/2006 02:18a 266 HelloWorldApp.java
06/19/2006 02:14a <DIR> Program Files
06/19/2006 02:18a <DIR> WINNT
2 File(s) 698 bytes
3 Dir(s) 1,114,345,472 bytes free

C:\>java HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldApp

C:\>type HelloWorldApp
The system cannot find the file specified.

C:\>type HelloWorldApp.java
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}

C:\>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\Administrator\Application Data
ClassPath=C:\Program Files\Java\jdk1.5.0_07\lib\tools.jar
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GEIDIPRIME
ComSpec=C:\WINNT\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\
LOGONSERVER=\\GEIDIPRIME
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program
Files\Java\jdk1.5.0_07\bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0304
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
USERDOMAIN=GEIDIPRIME
USERNAME=Administrator
USERPROFILE=C:\Documents and Settings\Administrator
windir=C:\WINNT

C:\>
C:\>
C:\>
C:\>
C:\>
C:\>
C:\>java -cp . HelloWorldApp
Hello World!

C:\>

I need the classpath option? What's the point of the CLASSPATH
environment variable, then?


The source code:

<http://java.sun.com/docs/books/tutorial/getStarted/application/ex5/HelloWorldApp.java>

<http://java.sun.com/j2se/1.5.0/install-windows.html> says to:
'Microsoft Windows NT, 2000, and XP - To set the PATH permanently:

1. Choose Start, Settings, Control Panel, and double-click System.
On Microsoft Windows NT, select the Environment tab; on Microsoft
Windows 2000 select the Advanced tab and then Environment Variables.
Look for "Path" in the User Variables and System Variables. If you're
not sure where to add the path, add it to the right end of the "Path"
in the User Variables. A typical value for PATH is:

C:\Program Files\Java\jdk1.5.0_<version>\bin

Capitalization doesn't matter. Click "Set", "OK" or "Apply".

The PATH can be a series of directories separated by semi-colons
(;). Microsoft Windows looks for programs in the PATH directories in
order, from left to right. You should only have one bin directory for a
JDK in the path at a time (those following the first are ignored), so
if one is already present, you can update it to jdk1.5.0_<version>\bin.

2. The new path takes effect in each new Command Prompt window you
open after setting the PATH variable. '

Which I believe I've done correctly. However, the word "classpath"
doesn't occur on that page, which is the problem.


<http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html>

gives an example of executing a .class file:


' To run that app, you could use the following JVM command:

C:> java -classpath C:\java\MyClasses utility.myapp.Cool '


So, to execute HelloWorldApp, the java command
requires the classpath as an argument?

Or, do I have the CLASSPATH environment variable
incorrectly set?

<http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html>:

'-classpath classpath
-cp classpath
Specify a list of directories, JAR archives, and ZIP archives to
search for class files. Class path entries are separated by semicolons
(;). Specifying -classpath or -cp overrides any setting of the
CLASSPATH environment variable.

If -classpath and -cp are not used and CLASSPATH is not set, the
user class path consists of the current directory (.).

For more information on class paths, see Setting the Class Path. '


I want to minimize my usage of the classpath option
when running and compiling HelloWorldApp, or similar
code.


thanks,

Thufir

Ed Kirwan

unread,
Jun 20, 2006, 4:22:26 AM6/20/06
to
hawat....@gmail.com wrote:
> How do I execute HelloWorldApp, please?
>
>
> Microsoft Windows 2000 [Version 5.00.2195]
> (C) Copyright 1985-2000 Microsoft Corp.
>
> C:\>dir
> Volume in drive C has no label.
> Volume Serial Number is FCD2-42DE
>
> Directory of C:\
>
> 11/21/2005 11:15p <DIR> Documents and Settings
> 06/19/2006 02:18a 266 HelloWorldApp.java
> 06/19/2006 02:14a <DIR> Program Files
> 06/19/2006 02:18a <DIR> WINNT
> 1 File(s) 266 bytes
> 3 Dir(s) 1,114,669,056 bytes free
>
> C:\>javac HelloWorldApp.java
>
> C:\>dir
> Volume in drive C has no label.
> Volume Serial Number is FCD2-42DE
>

> }
>

> C:\>set
> ALLUSERSPROFILE=C:\Documents and Settings\All Users
> APPDATA=C:\Documents and Settings\Administrator\Application Data
> ClassPath=C:\Program Files\Java\jdk1.5.0_07\lib\tools.jar
> CommonProgramFiles=C:\Program Files\Common Files
> COMPUTERNAME=GEIDIPRIME
> ComSpec=C:\WINNT\system32\cmd.exe
> HOMEDRIVE=C:

> thanks,
>
> Thufir
>

Remove that environment variable:


ClassPath=C:\Program Files\Java\jdk1.5.0_07\lib\tools.jar

--
www.EdmundKirwan.com - Home of The Fractal Class Composition.

Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html

jcsnippets.atspace.com

unread,
Jun 20, 2006, 5:02:04 PM6/20/06
to
<hawat....@gmail.com> wrote in message
news:1150790084.9...@i40g2000cwc.googlegroups.com...

> How do I execute HelloWorldApp, please?

1. Compile with javac HelloWorldApp.java
2. Run with java HelloWorldApp

To be able to execute HelloWorldApp, you need to make sure the current
directory is part of the classpath. Currently, it isn't so, and that's why
you need to add the "-cp ." part, to indicate that the current directory
needs to be searched for classes to execute.

Anyway, here are two ways to set your classpath:
1. execute in a command window:
set CLASSPATH=%CLASSPATH%;.;
this adds the current directory to the already existing classpath
2. go to settings / control panel / system, open the advanced tab, and click
'environment variables'
look under system variables and add or edit the classpath variable

I saw that you are on Windows 2000, so this should work on your machine.

Best regards,

JayCee
--
http://jcsnippets.atspace.com/
a collection of source code, tips and tricks


hawat....@gmail.com

unread,
Jun 21, 2006, 3:19:05 AM6/21/06
to
Ed Kirwan wrote:
[...]

> Remove that environment variable:
> ClassPath=C:\Program Files\Java\jdk1.5.0_07\lib\tools.jar
[...]

this worked:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>set


ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\Administrator\Application Data

CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GEIDIPRIME
ComSpec=C:\WINNT\system32\cmd.exe

GROOVY_HOME=C:\Program Files\Java\jdk1.5.0_07\bin
HOMEDRIVE=C:
HOMEPATH=\
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_07\bin


LOGONSERVER=\\GEIDIPRIME
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program
Files\Java\jdk1.5.0_07\bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0304
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
USERDOMAIN=GEIDIPRIME
USERNAME=Administrator
USERPROFILE=C:\Documents and Settings\Administrator
windir=C:\WINNT

C:\>dir


Volume in drive C has no label.
Volume Serial Number is FCD2-42DE

Directory of C:\

11/21/2005 11:15p <DIR> Documents and Settings

06/19/2006 02:46a 432 HelloWorldApp.class


06/19/2006 02:18a 266 HelloWorldApp.java

06/19/2006 03:34a <DIR> news
06/19/2006 11:16p <DIR> Program Files
06/20/2006 12:43a <DIR> WINNT
2 File(s) 698 bytes
4 Dir(s) 924,237,824 bytes free

C:\>java HelloWorldApp
Hello World!

C:\>

thanks,

Thufir

hawat....@gmail.com

unread,
Jun 21, 2006, 3:46:39 AM6/21/06
to


This worked:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>set


ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\Administrator\Application Data

CLASSPATH=%CLASSPATH%;.;


CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GEIDIPRIME
ComSpec=C:\WINNT\system32\cmd.exe

GROOVY_HOME=C:\Program Files\Java\jdk1.5.0_07\bin
HOMEDRIVE=C:
HOMEPATH=\
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_07\bin


LOGONSERVER=\\GEIDIPRIME
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program
Files\Java\jdk1.5.0_07\bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0304
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
USERDOMAIN=GEIDIPRIME
USERNAME=Administrator
USERPROFILE=C:\Documents and Settings\Administrator
windir=C:\WINNT

C:\>dir


Volume in drive C has no label.
Volume Serial Number is FCD2-42DE

Directory of C:\

11/21/2005 11:15p <DIR> Documents and Settings

06/19/2006 02:46a 432 HelloWorldApp.class


06/19/2006 02:18a 266 HelloWorldApp.java

06/19/2006 03:34a <DIR> news
06/19/2006 11:16p <DIR> Program Files

06/20/2006 12:43a <DIR> WINNT
2 File(s) 698 bytes
4 Dir(s) 928,235,520 bytes free

C:\>java HelloWorldApp
Hello World!

C:\>
C:\>
C:\>


I dunno. I went to a bookstore and looked this up, it was something
like "learn Java in 24 hours," or of that ilk, and it had specific
instructions for each of the Windows flavors. I thought I copied it
down correctly, but guess not :(


Thanks,

Thufir

hawat....@gmail.com

unread,
Jun 22, 2006, 2:56:29 AM6/22/06
to
I'm trying to add groovy and seem to have inadvertently broken
JAVA_HOME :(

I tried setting JAVA_HOME so that it does, and doesn't have a \bin on
the tail end, and so that the \bin is and isn't, respectively,
reflected in the PATH environment variable.

It's late, I'm tired and will continue this tomorrow. I've seen
references to other JAVA_HOME and PATH settings, and, as far as I can
tell, I have it correctly done. Nope?

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>java
'java' is not recognized as an internal or external command,
operable program or batch file.

C:\>javac
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\>groovy
'groovy' is not recognized as an internal or external command,
operable program or batch file.

C:\>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\Administrator\Application Data

CLASSPATH=%CLASSPATH%;.;;.;;.;


CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GEIDIPRIME
ComSpec=C:\WINNT\system32\cmd.exe

GROOVY_HOME=C:\Program Files\groovy-1.0-jsr-05\bin


HOMEDRIVE=C:
HOMEPATH=\
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_07\bin
LOGONSERVER=\\GEIDIPRIME
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;

Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;GROOVY_HOME;JAVA_HOME


PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0304
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
USERDOMAIN=GEIDIPRIME
USERNAME=Administrator
USERPROFILE=C:\Documents and Settings\Administrator
windir=C:\WINNT

C:\>

and then


Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\Administrator\Application Data

CLASSPATH=%CLASSPATH%;.;;.;;.;


CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GEIDIPRIME
ComSpec=C:\WINNT\system32\cmd.exe

GROOVY_HOME=C:\Program Files\groovy-1.0-jsr-05


HOMEDRIVE=C:
HOMEPATH=\
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_07

LOGONSERVER=\\GEIDIPRIME
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;

Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;GROOVY_HOME\bin;JAVA_HOME\bin


PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0304
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
USERDOMAIN=GEIDIPRIME
USERNAME=Administrator
USERPROFILE=C:\Documents and Settings\Administrator
windir=C:\WINNT

C:\>java
'java' is not recognized as an internal or external command,
operable program or batch file.

C:\>javac
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\>groovy
'groovy' is not recognized as an internal or external command,
operable program or batch file.

C:\>dir C:\Program Files\groovy-1.0-jsr-05


The system cannot find the file specified.

C:\>cd C:\Program Files\groovy-1.0-jsr-05

C:\Program Files\groovy-1.0-jsr-05>dir


Volume in drive C has no label.
Volume Serial Number is FCD2-42DE

Directory of C:\Program Files\groovy-1.0-jsr-05

06/21/2006 12:43a <DIR> .
06/21/2006 12:43a <DIR> ..
06/21/2006 12:44a <DIR> bin
06/21/2006 12:43a <DIR> conf
06/21/2006 12:44a <DIR> docs
06/21/2006 12:43a <DIR> embeddable
02/13/2006 11:48p 1,249,664 groovy-1.0-jsr-05.jar
06/21/2006 12:44a <DIR> lib
02/13/2006 11:48p 1,978 LICENSE.txt
2 File(s) 1,251,642 bytes
7 Dir(s) 878,063,616 bytes free

C:\Program Files\groovy-1.0-jsr-05>
C:\Program Files\groovy-1.0-jsr-05>
C:\Program Files\groovy-1.0-jsr-05>

thanks,

Thufir

0 new messages