wood burning stoves*
The moose likes Beginning Java and the fly likes Java Package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Package" Watch "Java Package" New topic
Author

Java Package

Jessica Lang
Ranch Hand

Joined: Jul 23, 2002
Posts: 61
Hello everybody,
Currently, I am using the �SCP for Java 2 (Second Edition) � Syngress� book as a reference. In it�s first chapter (Language Fundamental - Exercise 1-2: Creating a Package and Inserting Classes � pg. 7), I tried the sample but has been unsuccessful. I am able to compiled the MyClass.java file but not running it. Below are the details:
>>> I have created 2 directories:
�C:\mypgms\Osborne� <== Stores the MyClass.java source file
�C:\mypackages\com\syngress� <== Stores the MyClass.class file

>>> MyClass.java source file is as follow:
package com.syngress;
public class MyClass {
public static void main (String[] args) {
System.out.println ("This is demo on setting up JAVA PACKAGE");
}
}

>>> The WinXP OS�s Environment variable for Path is set as follow:
C:\mypgms\Osborne>path
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Co
mmon Files\Adaptec Shared\System;C:\PROGRA~1\IBM\CLIENT~1;C:\PROGRA~1\IBM\CLIENT
~1\Shared;C:\PROGRA~1\IBM\CLIENT~1\Emulator;C:\j2sdk1.4.0\bin\.;C:\mypackages\.;

>>> Successful compilation: MyClass.class is created in the �C:\mypackages\com\syngress� path
C:\mypgms\Osborne>javac MyClass.java -d c:\mypackages\

>>> HOWEVER, the following failed:
C:\mypgms\Osborne>java com.syngress.MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: com/syngress/MyClass

Does anyone know where can I get the errata for this book?
Thanks for the help�.:-)
Jessica Lang
Ranch Hand

Joined: Jul 23, 2002
Posts: 61
Hi everyone,
I managed to find the URL for the book's errata at the following URL (rite after I have posted the message):
http://www.osborne.com/errata/errata.shtml
Thanks!....
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
C:\mypgms\Osborne>java com.syngress.MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: com/syngress/MyClass

You should have your CLASSPATH variable set to include C:\mypackages, for java com.syngress.MyClass to work if you want to run it from C:\mypgms\Osborne
For this simple test program you should be able to use: java -cp C:\mypackages com.syngress.MyClass
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jessica Lang
Ranch Hand

Joined: Jul 23, 2002
Posts: 61
Hi all,
I managed to find the cause to the error. I didn't know that PATH and CLASSPATH are two separate things.
I set the following to the CLASSPATH:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%;C:\mypackages\.;
and it is fine now.
Earlier on, the above "c:\mypackages\.;" was set at the PATH variable!!!
I also found out that the following will work too (issued at the DOS Command line) if the CLASSPATH variable is not set accordingly:
>>> Display the current directory �Classpath�
C:\mypgms\Osborne>set classpath
Environment variable classpath not defined
>>> Set the needed �Classpath�
C:\mypgms\Osborne>set classpath=c:/mypackages/
C:\mypgms\Osborne>set classpath
classpath=c:/mypackages/
>>> Run the MyClass program accordingly
C:\mypgms\Osborne>java com.syngress.MyClass
This is demo on setting up JAVA PACKAGE
Thanks to the useful helps (Barry) and messages in this forums.....
 
GeeCON Prague 2014
 
subject: Java Package