Results 1 to 10 of 10
  1. #1
    BernieC is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Executing the JAR File - ANT HelloWorld Tutorial

    I'm going thru the HelloWorld tutorial in ANT. I've executed the echo command to create a manifest and created the HelloWorld.jar file using the manifest. When I try to execute the jar file (C:\ANT>java -jar Build\jar\HelloWorld.jar), I get " Cannot find or load main class oata.HelloWorld". If this class is in the jar file that is being executed, why is it not found?

    Directory structure is as follows:

    C:\Ant
    C:\ANT\build
    C:\ANT\build\classes
    C:\ANT\build\classes\oata
    C:\ANT\build\classes\oata\HelloWorld.class
    C:\ANT\build\jar
    C:\ANT\build\jar\HelloWorld.jar


    Thanks

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    Yes, but what is in the jar file?
    Have you retained the package structure such that there is an 'oata' "folder" in the top level of the jar file, containing your class?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    BernieC is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    Yes. The jar file has a META-INF folder which contains MANIFEST.MF. The jar file also contains "build/classes/oata/HelloWorld.class"

  4. #4
    BernieC is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    Wait a minute. The "oata" folder is not the top level folder. Is that my problem?

    Thanks

  5. #5
    BernieC is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    Thanks for the help. The piece of data I was missing was that the "oata" folder needed to be the top level folder in the jar file
    I figured this out how to make that happen.

    Key points: 1. before executing the jar command one must change the directory to the the path of the class file . in my case "C:>ANT\build\classes".
    2. if one wants the new jar file to be in a folder other than the "classes" folder, one must enter the full path. In my case "C:\build\jar\HelloWorld.jar".

    One other note . If I used the -C parameter before the class file folder name, a jar file was not created. I had to leave out the "-C" to make it work. I don't know what is going on there.

    .

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    What is the full command you are using when using the -C option, and where are you located when you do that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    BernieC is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    The following will not produce a jar file:

    "C:\ANT\build\classes>jar -cfm C:\ANT\build\jar\HelloWorld.jar myManifest -C oata/"


    The following DOES produce a jar file:


    "C:\ANT\build\classes>jar -cfm C:\ANT\build\jar\HelloWorld.jar myManifest oata/"

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    The -C just tells it to change directory to the given directory (oata in your case).
    So in that first command you have only told the jar command to change directory...but you haven't given it anything to jar up.

    jar -cfm C:\ANT\build\jar\HelloWorld.jar myManifest -C oata .

    That '.' there tells it you want to jar up the contents of the current directory, in this case the contents of 'oata' since that is current as of the '-C'.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    BernieC is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    That works. I didn't know you needed the period.



    Thanks again!!

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Executing the JAR File - ANT HelloWorld Tutorial

    The period tells jar that you want to jar the files in the current directory.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Executing a jar file
    By peiceonly in forum New To Java
    Replies: 7
    Last Post: 02-14-2014, 09:02 AM
  2. Executing a executable .jar file
    By angrylolrus in forum New To Java
    Replies: 3
    Last Post: 11-26-2012, 06:00 AM
  3. Trouble executing a file!
    By javabeginner29 in forum New To Java
    Replies: 1
    Last Post: 02-26-2012, 09:29 AM
  4. Problem executing jar file
    By gio123bg in forum New To Java
    Replies: 4
    Last Post: 06-30-2009, 11:37 AM
  5. executing the java file
    By TheBayWatchMan in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 09:31 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
  •