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 12 of 12

Thread: java -jar path problem

  1. #1
    Junior Member lostbits's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java -jar path problem

    win7
    cygwin 1.7.25

    I've done something dumb but I can't figure out what it is, sigh. I installed ANTLR into my /usr/local/lib (C:\cygwin\usr\local\lib), fixed the CLASSPATH variable so that ANTLR is first and put /usr/local/lib into my (cygwin) PATH variable. Java is installed into C:\Program Files\Java.

    Using a bash shell (in cygwin)
    java works
    java -jar /usr/local/lib/antlr.. does not work (Unable to access jarfile /usr/local/lib/antlr-4.1-complete.jar)
    cd /usr/local/lib
    java -jar antlr .. works just fine

    Under a DOS shell
    java works
    java -jar c:\cywin\usr\local\lib\antlr ... does not work

    What have I done wrong? What am I missing?


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

    Default Re: java -jar path problem

    java -jar antlr .. works just fine
    I didn't know that the -jar option would work without a jar file name. Are you sure that there isn't a jar file named antir in the directory where the java -jar command is issued?
    The following worked. BuildDoIt is a jar file that was renamed by removing the .jar:
     
     Directory of C:\Testing
     
    09/21/2004  03:18 PM            25,660 BuildDoIt
                   1 File(s)         25,660 bytes
                   0 Dir(s)  52,036,771,840 bytes free
     
    C:\Testing>java -jar BuildDoIt
     
    C:\Testing>
     
    C:\Testing>cd ..
     
    C:\>java -jar C:/Testing/BuildDoIt
     
    C:\>

    does not work
    Please copy the full contents of the command prompt window and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: java -jar path problem

    Hello.
    I tried in Ubuntu.
    It worked well.
    Can you try again?

    Syed.

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

    Default Re: java -jar path problem

    @syed Can you copy the contents of the console and post it showing the filename and the command line used?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: java -jar path problem

    Hello.
    Sure. Please find attached the screenshot. I wanted to attached the executable jar as well but looks like I can't do that.
    If you get any questions please let me know.
    The executable jar "Exec.jar" was available in the JarTest2 folder.
    I switched to some other directory. From there I executed the jar file.

    Thanks,
    Syed.Screenshot.jpg

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

    Default Re: java -jar path problem

    @Syed Can you COPY and PASTE the contents of the console window here? I can't do a FIND on text in an image.
    For example I want to see the java command:
    java -jar <Path to jar file>

    The main question I have is can you use the java -jar command without specifying the name of the jar file The OP/user implies that he was able to have it execute by giving the path to a folder, NOT the path to a jar file.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member lostbits's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Re: java -jar path problem

    It's an environmental issue. Java is installed on a Win7 machine and expects a Win7 formatted path. I dislike Win-anything and run using a (cygwin) bash shell. Bash shell paths 'know' that the root is '/'. Java does not know that '/' means 'C:/'. And so, the mystery ends.

    Thank you all. You got me to think of a 'novel' way to (again) prove that I used to be smart, and then changed my mind.

    art

    ~ >> java -jar /usr/local/lib/antlr-4.1-complete.jar
    Error: Unable to access jarfile /usr/local/lib/antlr-4.1-complete.jar
    ~ >> java -jar 'C:\cygwin64\usr\local\lib\antlr-4.1-complete.jar' # or
    ~ >> java -jar c:/cygwin64/usr/local/lib/antlr-4.1-complete.jar

    ANTLR Parser Generator Version 4.1
    -o ___ specify output directory where all output is generated
    -lib ___ specify location of grammars, tokens files
    -atn generate rule augmented transition network diagrams
    -encoding ___ specify grammar file encoding; e.g., euc-jp
    -message-format ___ specify output style for messages in antlr, gnu, vs2005
    -long-messages show exception details when available for errors and warnings
    -listener generate parse tree listener (default)
    -no-listener don't generate parse tree listener
    -visitor generate parse tree visitor
    -no-visitor don't generate parse tree visitor (default)
    -package ___ specify a package/namespace for the generated code
    -depend generate file dependencies
    -D<option>=value set/override a grammar-level option
    -Werror treat warnings as errors
    -XdbgST launch StringTemplate visualizer on generated code
    -XdbgSTWait wait for STViz to close before continuing
    -Xforce-atn use the ATN simulator for all predictions
    -Xlog dump lots of logging info to antlr-timestamp.log

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

    Default Re: java -jar path problem

    Bash shell paths 'know' that the root is '/'. Java does not know that '/' means 'C:/
    I have 3 drives on Win7: C:, D: and E: what would the root be for that?

    This worked for me:
     
    C:\>java -jar /Testing/BuildDoit
     
    C:\>
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member lostbits's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java -jar path problem

    I hear you. The root I was talking about was the UNIX root, '/', established in cygwin. I put this root on the C: drive. Most specifically, C:/cygwin64 in DOS is '/' in cygwin. It appears that java does not understand that '/' really means C:/cygwin64. When I put my path in as "java -jar c:/cygwin64/usr/local/lib/antlr...jar" it works. Nothing else does.

    When you put in '/Testing/BuildDoit' I don't know what happen. I guess you are running under Win7 and that (you are saying) that Testing/BuildDoit is located on one of the drives, C:, D:, or E:, and that Win7 translates '/' to the appropriate drive and path? I don't know how you did it but it doesn't seem to work for me. So, how did you construct your system so that java recognizes the root, '/', and translates the root into the correct path? Where is Testing/BuildDoit located? Is the directory Testing located at C:/Testing or is Testing located at some other place (D:/.../Testing for example)?

    art

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

    Default Re: java -jar path problem

    The post shows that I was in C: (root)
    The full path to the jar file: C:/Testing/BuildDoIt
    I guess java took the /Testing path to mean: start in the current location and go to the folder: Testing
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member lostbits's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java -jar path problem

    Well, I aint an expert (as this post clearly shows) but that would be my guess. If you locate Testing/ at any other location (D:/Testing, E:/Testing, or C:/.../Testing) I would guess that it won't work.

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

    Default Re: java -jar path problem

    I would guess that it won't work.
    That's right. The path/folder needs to be where the java program can see it.
    It would work if the current directory (where ever that is) contained a folder: Testing
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. System cannot find path specified in a jar?
    By 847295 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 24th, 2013, 07:54 AM
  2. How to convert local path drive to UNC path
    By krisswift in forum Object Oriented Programming
    Replies: 2
    Last Post: November 17th, 2011, 08:40 AM
  3. Relative path issue with Context path struts
    By chinnu in forum Web Frameworks
    Replies: 1
    Last Post: March 31st, 2011, 10:17 AM
  4. locating the path to a jar file within a program
    By nemo in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 2nd, 2011, 05:41 PM
  5. how to get full path name from realtive path
    By priyanka3006 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: August 10th, 2009, 04:28 AM

Tags for this Thread