• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Java Package

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!....
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Jessica Lang
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
 
The moustache of a titan! The ad of a flea:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic