Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: current directory not dectected by java application launcher in command prompt

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    28
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question current directory not dectected by java application launcher in command prompt

    Here is the following scenario

    my classpath in environment variables is .;D/Javarohan; (current directory already specified)

    my files are in location D:/Javarohan/In2

    Filename in In2 directory is Bwoi.java (i have written the package statement in the Bwoi.java file.....package In2

    Now when i go to command prompt and go to the directory and issue the javac as

    D:/Javarohan/In2>javac Bwoi.java [Compiles fine]

    and next

    D:/javarohan/In2> java Bwoi [Press enter]

    I get the following no class definition found error

    and if i isuue command like below

    D:/Javarohan/In2> java In2.Bwoi [I am getting hte right output]


    cmdprmt.jpg

    I mean when i am in the required directory as according to my CLASSPATH set [.;D/Javarohan;],why should i explicitly issue
    the command java In2.Bwoi..Why doesnt it work with java Bwoi ?. This clearly means java application
    launcher is not detecting my current directory when i have already specified the dot operator in
    CLASSPATH ->.;.D/Javarohan;

    is there any solutions for running it in thru command promt by going into the directory D:/Javarohan/In2
    and issuing a command like this->java Bwoi

    What are the changes i need to do as far as CLASSPATH goes and my package statement in Bwoi.java file?

    Please help me out guys ! its funny but serious


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: current directory not dectected by java application launcher in command prompt

    To execute a class in a package, you need to position the current directory to the directory containing the top of the package path folder and use the full package path for the class.
    For a package in In2, go to the folder containing In2 (Jovarohn) and enter:
    java In2.Bwoi

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    28
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: current directory not dectected by java application launcher in command prompt

    Hey thanks for ur timely reply(Ya i will do it like u said for command prompt copying....sorry for putting up an image).
    But my problem is unsolved.Why should i once again say java In2.Bwoi after compiling to execute it whereas i have already included the current
    directory in my classpath and both .class file and source file of Bwoi is in In2 folder.And I am in In2 directory in command prompt. why cannot it be directly java Bwoi instead of java In2.Bwoi since JVM searches for .class file in my current directory.I guess it might be a compulsory rule

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: current directory not dectected by java application launcher in command prompt

    If a class is in a package then the classpath must point to the start of the package path.
    The fully qualified name of the class includes the package. Bwoi is not the full name of the class. It needs to have the package also.
    If you know how many directory levels you must go up to get the the beginning of the package path you can use: ..\ in your classpath.
    For example, if you are in the In2 folder:
    java -cp ..\. In2.Bwoi

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: current directory not dectected by java application launcher in command prompt

    the file name needs to be the same as the class name. If the class name is In2, then the file name should be In2.java.

Similar Threads

  1. Java on command prompt
    By Tanmaysinha in forum What's Wrong With My Code?
    Replies: 12
    Last Post: August 17th, 2011, 06:45 AM
  2. command prompt, acquiring input without enter?
    By kitube in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 24th, 2011, 10:14 PM
  3. [SOLVED] can't run javac directly from command prompt
    By epezhman in forum Java IDEs
    Replies: 7
    Last Post: January 12th, 2011, 07:38 PM
  4. [SOLVED] Redirect command prompt output to log file.
    By goldest in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: November 24th, 2010, 05:26 AM
  5. Strange launch problem using command prompt
    By Asido in forum Java Theory & Questions
    Replies: 2
    Last Post: September 15th, 2010, 07:52 AM