Results 1 to 3 of 3
  1. #1
    beezerbutt is offline Member
    Join Date
    Feb 2009
    Location
    South Africa
    Posts
    18
    Rep Power
    0

    Default [SOLVED] Why does -cp work on Unix but not on XP?

    hi

    Before you flame me into the "beginner" section of this forum, just read the following trace; it has been driving me insane for the past 3 days...
    The SAME java program will not run given the same application of Classpath options on XP and Unix...and as a LOT of development happens on XP i simply must understand what i am doing wrong!!!
    All i am trying to do is to run a helloworld program using the -cp options of java...

    Here is the Unix Trace (that behaves as it should): :)
    ------------------------------------------------
    [jill@gmnbq8aa ~]$ pwd
    /home/jill
    [jill@gmnbq8aa ~]$ cd compiling/
    [jill@gmnbq8aa ~/compiling]$ cd com
    -bash: cd: com: No such file or directory
    [jill@gmnbq8aa ~/compiling]$ cd src
    [jill@gmnbq8aa ~/compiling/src]$ cd com
    [jill@gmnbq8aa ~/compiling/src/com]$ cd psg
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ ls
    Ass.class Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ more Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ type Ass.java
    -bash: type: Ass.java: not found
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ echo Ass.java
    Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ cls
    -bash: cls: command not found
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ clear
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ cd
    [jill@gmnbq8aa ~]$ cler
    -bash: cler: command not found
    [jill@gmnbq8aa ~]$ clear
    [jill@gmnbq8aa ~]$ pwd
    /home/jill
    [jill@gmnbq8aa ~]$ cd compiling/src/com/psg/
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ ls
    Ass.class Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ ls -al
    total 11
    drwxr-xr-x 2 jill jill 4 Apr 18 13:15 .
    drwxr-xr-x 3 jill jill 3 Apr 18 13:06 ..
    -rw-r--r-- 1 jill jill 425 Apr 18 13:21 Ass.class
    -rw-r--r-- 1 jill jill 131 Apr 18 13:21 Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ more Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ man more
    Reformatting page. Please Wait... done
    [jill@gmnbq8aa ~/compiling/src/com/psg]$
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ cat Ass.java
    package com.psg;

    public class Ass {
    public static void main (String[] args) {
    System.out.println("Heelo curel world");
    }
    }
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ cd ../../../classes/
    [jill@gmnbq8aa ~/compiling/classes]$ ll
    total 3
    drwxr-xr-x 3 jill jill 3 Apr 18 13:28 com/
    [jill@gmnbq8aa ~/compiling/classes]$ cd com/psg
    [jill@gmnbq8aa ~/compiling/classes/com/psg]$ ll
    total 2
    -rw-r--r-- 1 jill jill 425 Apr 18 13:28 Ass.class
    [jill@gmnbq8aa ~/compiling/classes/com/psg]$ rm Ass.class
    [jill@gmnbq8aa ~/compiling/classes/com/psg]$ cd ../../../src/com/psg
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ ll
    total 5
    -rw-r--r-- 1 jill jill 425 Apr 18 13:21 Ass.class
    -rw-r--r-- 1 jill jill 131 Apr 18 13:21 Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ rm Ass.class
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ javac -Xms256m -d ../../../classes
    javac: invalid flag: -Xms256m
    Usage: javac <options> <source files>
    use -help for a list of possible options
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ javac -XMs256m -d ../../../classes Ass.java
    javac: invalid flag: -XMs256m
    Usage: javac <options> <source files>
    use -help for a list of possible options
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ javac -d ../../../classes Ass.java
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ ll ../../../classes/com/psg/
    total 1
    -rw-r--r-- 1 jill jill 425 Apr 19 08:15 Ass.class
    [jill@gmnbq8aa ~/compiling/src/com/psg]$ cd ../../../
    [jill@gmnbq8aa ~/compiling]$ cd classes
    [jill@gmnbq8aa ~/compiling/classes]$ java -Xms256m -cp .: com/psg/Ass
    Heelo curel world
    [jill@gmnbq8aa ~/compiling/classes]$

    ----------------------------------

    ..and here is the dysfunctional XP output (that does not behave as it shoul): :mad:
    ===============================
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\kshAdministrator.DARIUS2>d:

    D:\>cd compiling

    D:\compiling>dir
    Volume in drive D is Telkom
    Volume Serial Number is E7E9-FB01

    Directory of D:\compiling

    04/18/2009 02:23 PM <DIR> .
    04/18/2009 02:23 PM <DIR> ..
    04/18/2009 02:28 PM <DIR> classes
    04/18/2009 02:23 PM <DIR> src
    0 File(s) 0 bytes
    4 Dir(s) 6,603,919,360 bytes free

    D:\compiling>cd src

    D:\compiling\src>dir
    Volume in drive D is Telkom
    Volume Serial Number is E7E9-FB01

    Directory of D:\compiling\src

    04/18/2009 02:23 PM <DIR> .
    04/18/2009 02:23 PM <DIR> ..
    04/18/2009 02:23 PM <DIR> com
    0 File(s) 0 bytes
    3 Dir(s) 6,603,919,360 bytes free

    D:\compiling\src>cd com

    D:\compiling\src\com>dir
    Volume in drive D is Telkom
    Volume Serial Number is E7E9-FB01

    Directory of D:\compiling\src\com

    04/18/2009 02:23 PM <DIR> .
    04/18/2009 02:23 PM <DIR> ..
    04/18/2009 03:33 PM <DIR> psg
    0 File(s) 0 bytes
    3 Dir(s) 6,603,919,360 bytes free

    D:\compiling\src\com>cd psg

    D:\compiling\src\com\psg>dir
    Volume in drive D is Telkom
    Volume Serial Number is E7E9-FB01

    Directory of D:\compiling\src\com\psg

    04/18/2009 03:33 PM <DIR> .
    04/18/2009 03:33 PM <DIR> ..
    04/18/2009 03:33 PM 135 Ass.java
    1 File(s) 135 bytes
    2 Dir(s) 6,603,919,360 bytes free

    D:\compiling\src\com\psg>type Ass.java
    package com.psg;

    class Ass {

    public static void main (String[] args) {
    System.out.println("Catching fishes all day");
    }
    }
    D:\compiling\src\com\psg>cd ..\..\..\classes

    D:\compiling\classes>dir
    Volume in drive D is Telkom
    Volume Serial Number is E7E9-FB01

    Directory of D:\compiling\classes

    04/18/2009 02:28 PM <DIR> .
    04/18/2009 02:28 PM <DIR> ..
    04/18/2009 02:28 PM <DIR> com
    0 File(s) 0 bytes
    3 Dir(s) 6,603,919,360 bytes free

    D:\compiling\classes>cd com

    D:\compiling\classes\com>cd psg

    D:\compiling\classes\com\psg>dir
    Volume in drive D is Telkom
    Volume Serial Number is E7E9-FB01

    Directory of D:\compiling\classes\com\psg

    04/18/2009 03:56 PM <DIR> .
    04/18/2009 03:56 PM <DIR> ..
    04/18/2009 03:56 PM 431 Ass.class
    1 File(s) 431 bytes
    2 Dir(s) 6,603,919,360 bytes free

    D:\compiling\classes\com\psg>del Ass.class

    D:\compiling\classes\com\psg>cd ..\..\..\src

    D:\compiling\src>cd com\psg

    D:\compiling\src\com\psg>javac -d ..\..\..\classes A
    'javac' is not recognized as an internal or external command,
    operable program or batch file.

    D:\compiling\src\com\psg>set path=%path%;"C:\Program Files\Java\jdk1.5.0_06\bin"

    D:\compiling\src\com\psg>javac -d ..\..\..\classes A
    javac: invalid flag: A
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are used
    -classpath <path> Specify where to find user class files
    -cp <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system


    D:\compiling\src\com\psg>set path=%path%;.

    D:\compiling\src\com\psg>javac -d ..\..\..\classes A
    javac: invalid flag: A
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are used
    -classpath <path> Specify where to find user class files
    -cp <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system


    D:\compiling\src\com\psg>javac -d ..\..\..\classes Ass
    javac: invalid flag: Ass
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are used
    -classpath <path> Specify where to find user class files
    -cp <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system


    D:\compiling\src\com\psg>javac -d ..\..\..\classes .\Ass.java

    D:\compiling\src\com\psg>cd ..\..\..

    D:\compiling>cd classes

    D:\compiling\classes>java -cp .; Ass
    Exception in thread "main" java.lang.NoClassDefFoundError: Ass

    D:\compiling\classes>java -cp .; D:\compiling\classes\com\psg\Ass
    Exception in thread "main" java.lang.NoClassDefFoundError: D:\compiling\classes\com\psg\Ass

    D:\compiling\classes>cd ..

    D:\compiling>cd classes

    D:\compiling\classes>cd com

    D:\compiling\classes\com>cd psg

    D:\compiling\classes\com\psg>dir
    Volume in drive D is Telkom
    Volume Serial Number is E7E9-FB01

    Directory of D:\compiling\classes\com\psg

    04/19/2009 10:01 AM <DIR> .
    04/19/2009 10:01 AM <DIR> ..
    04/19/2009 10:01 AM 431 Ass.class
    1 File(s) 431 bytes
    2 Dir(s) 6,603,919,360 bytes free

    D:\compiling\classes\com\psg>java -cp D:\compiling\classes\com\psg;. .\Ass
    Exception in thread "main" java.lang.NoClassDefFoundError: /\Ass

    D:\compiling\classes\com\psg>java -cp D:\compiling\classes\com\psg;. D:\compiling\classes\com\psg\Ass.class
    Exception in thread "main" java.lang.NoClassDefFoundError: D:\compiling\classes\com\psg\Ass/class

    D:\compiling\classes\com\psg>cd ..

    D:\compiling\classes\com>cd ..

    D:\compiling\classes>java -cp .; .\com\psg\Ass.class
    Exception in thread "main" java.lang.NoClassDefFoundError: /\com\psg\Ass/class

    D:\compiling\classes>java -cp .; d:\compiling\classes\com\psg\Ass.class
    Exception in thread "main" java.lang.NoClassDefFoundError: d:\compiling\classes\com\psg\Ass/class

    D:\compiling\classes>

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Try java -cp D:\compiling\classes\ com.psg.Ass

    The classpath should be to where your packages start, and the class name should follow Java conventions
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    beezerbutt is offline Member
    Join Date
    Feb 2009
    Location
    South Africa
    Posts
    18
    Rep Power
    0

    Default

    Thanks VERY much OrangeDog...i appreciate the help greatly.

Similar Threads

  1. How to Extract EAR files in UNIX
    By RG18173 in forum Advanced Java
    Replies: 6
    Last Post: 12-12-2008, 08:21 AM
  2. [SOLVED] Swing and Unix
    By nwboy74 in forum AWT / Swing
    Replies: 9
    Last Post: 11-05-2008, 02:04 AM
  3. Communicate between Windows and UNIX
    By nwboy74 in forum Networking
    Replies: 10
    Last Post: 11-04-2008, 08:53 PM
  4. JAVA compilation error in UNIX
    By satish kumar in forum Advanced Java
    Replies: 9
    Last Post: 08-08-2008, 07:36 AM
  5. using java to login to unix
    By dowell in forum Advanced Java
    Replies: 4
    Last Post: 05-23-2008, 07:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •