Results 1 to 8 of 8

Thread: jar file

  1. #1
    intfxdx is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default jar file

    Hi guys this is my first post and i am really new to java. As a student in finance i used matlab and R and java is really complicated(very long, it takes 3 lines in matlab to read a file and making a chart, it takes 200 lines in java...) for me but i have to do some work. I created a project and then a single package then 5 .java files. now i want to crate a jar file... i searched a lot on the internet. i could create the file but when i run it, it runs only the first .java file.... although the other .java files are in the jar because when check the contents i can see clearly the names of the other .java files... what should i do so that the jar file reads all .java files ?
    thanks

  2. #2
    Join Date
    May 2011
    Location
    Maryland
    Posts
    38
    Rep Power
    0

    Default

    can you be more specific about what you want it to do?
    it only runs one file at first but you can use that first class to access and run any of the other classes inside the jar as well

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It's not the .java files that matter when running a program, be it in a jar or not, but rather it's the .class files. Does your jar have the class files? Are your files in the proper packages? Are you getting any error messages when you try to run the program?

  4. #4
    intfxdx is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    i wrote 2 scripts that generates charts, i see the charts generated by the first script but not the second one when i run jar file. (program is correct because when i run it in netbeans everything is correct)
    and i think jar file is build correctly.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    when i run it, it runs only the first .java file
    Is there more than one java program in the jar file? Only one can be set to be the Main/starting program.
    When you execute a java program (in jar or on a disk) only one class is started. That class can use other classes as needed.

    There are other ways to execute a program from a jar file that would allow you to select which program to start:
    java -classpath THEJARFILENAME.jar TheStartingClassname

  6. #6
    intfxdx is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    what should i do so that jar file executes all programs ? i tried to call these other classes from the main one but all of them are like static void main, so that they don't return anything.. how i call a method from another class if it does not return anything but just save charts ?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Why not put each separate main-containing program in it's own Jar file. Either that or if you must have all in one Jar and have them all called one right after the other, then have a driver program which simply has a main method that calls all of the other class's main method.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    what should i do so that jar file executes all programs
    The jar file does NOT execute any programs. It is only a container of files(like a file system folder).
    The java command is what executes programs. It can execute class files that are in a folder and it can execute class files that are in a jar file.
    how i call a method from another class if it does not return anything
    You can call a method without it returning anything. No problem there. There are many methods that are "void".

Similar Threads

  1. Replies: 6
    Last Post: 12-01-2010, 05:31 AM
  2. Replies: 0
    Last Post: 07-15-2010, 01:23 PM
  3. Replies: 8
    Last Post: 02-18-2010, 12:54 PM
  4. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  5. Replies: 7
    Last Post: 05-23-2008, 03:46 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
  •