Results 1 to 11 of 11

Thread: .jar Help

  1. #1
    guitardenver is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default .jar Help

    So i've wrote many programs in java but never ran them outside the IDE. I have read a lot about creating .jar files. I wrote a simple and famous Hello World Class that just shows a JOption message pane that says Hello World. I use Eclipse with Windows 7. I exported the project in Eclipse to a JAR file. I go to the command line and do java -jar HelloWorld.jar and it runs my program just fine. This is not what I need to do. I want to be able to just double click on it and have it work. ON ANY COMPUTER I PUT IT ON. So I created a batch file that does the Command line stuff for me. I put the .jar file and my .bat file on a flash drive and put it on another computer (Windows 7 also with java 1.6) and I put the .jar file in the same directory my .bat file says it will be and the program DOES NOT RUN! WHY!!! What do I need to do to make an executable that portable??? And user friendly. People dont want to type CMD lines. Double Click and done. Thanks for the help!

  2. #2
    guitardenver is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default .jar Help

    So i've wrote many programs in java but never ran them outside the IDE. I have read a lot about creating .jar files. I wrote a simple and famous Hello World Class the just shows a JOption message pane that says Hello World. I use Eclipse with Windows 7. I exported the project in Eclipse to a JAR file. I go to the command line and do java -jar HelloWorld.jar and it runs my program just fine. This is not what I need to do. I want to be able to just double click on it and have it work. ON ANY COMPUTER I PUT IT ON. So I created a batch file that does the Command line stuff for me. I put the .jar file and my .bat file on a flash drive and put it on another computer (Windows 7 also with java 1.6) and I put the .jar file in the same directory my .bat file says it will be and the program DOES NOT RUN! WHY!!! Do I need to include another folder in the same directory as the .jar?? What do I need to do to make an executable thats portable??? And user friendly. People dont want to type CMD lines. Double Click and done. Thanks for the help!

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: .jar help

    Do you get any warning messages or anything? And can't your (non-linux) users just double click the jar to run it? Have you looked into webstart at all?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: .jar help

    Make an executable jar by sticking a proper Manifest file into the jar.
    That way the user can double click the jar and it should run.

    That should give you enough buzzwords to Google on.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: .jar Help

    I've moved this from the lobby.

    ON ANY COMPUTER I PUT IT ON. ... DOES NOT RUN! WHY!!!
    Calm down :)

    First of all let's note that .bat files are not applicable to any computer. They will be good for one OS only. For a couple of reasons: the OS must recognise the file as executable by virtue of its extension, and the commands contained within it must relate to a particular OS.

    Next, the "any computer" must contain a Java runtime.

    If the launching .bat file refers to a specific location on the end user's file system, that location must exist and the user must have the appropriate privileges to access it. (I mention this because the setup, as much as you have described it, is at variance with the stated aim of not making expectations of the user. Users don't - and shouldn't - have to type commands at the command line. But, equally, they shouldn't have to set up their file system in some particular way. And network administrators won't let them do so.)

    -----

    It might help if you described the problem: what does the .jar file contain? Specifically, what is its manifest? And what does the .bat file contain? What happens when the command(s) in the .bat file are typed at the command line of the target computer?

    Such a description should relate to the actual files you are deploying, rather than what you might have thought (or hoped) Eclipse was creating. In fact this raises the point that, to begin with, you might make more progress if you created the jar file and its classes and manifest by hand so that you could be confident of what you were creating. There is a good, illustrated, discussion of the process in the Packaging Programs in JAR Files section of Oracle's Tutorial.

    -----

    For your program I would have created an executable jar file, not a launching batch file. (All of the OSs/Desktop Managers I have worked with can be configured - at the *user's* discretion - to allow such jar files to be run via a double click.)

  6. #6
    guitardenver is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: .jar Help

    Thanks for the reply.

    I created the MANIFEST file manually like you said and also installed the JRE. And it works!!! I can put the .jar file anywhere and it works great.

    So I went ahead and created a .jar file for my real program (Not the Hello World). This also works great!. Unfortunately I'm still stuck with making the user put my file in a specific directory. I made one file that includes everything the user needs and the user only needs to copy and past that one file in the C: root directory.
    So that setup is very easy. I have to do this because my program creates txt files with a PrintWriter that are linked into a Excel Spreadsheet. Those txt files must be in a specific directory or the files will have to be re-linked into the Speadsheet. Not very easy for the user. So that means that I still have to create a .bat file to execute my .jar because the PrintWriter creates files in the directory that the .jar file is in. So they cant move the .jar file anywhere they want. But they can move a .bat file anywhere they want and when executed the .jar file creates the files in the right directory. And this approach works great. The excel document has no problem linking to the txt files and all the user has to do is double click on the .bat file and it works. (Assuming they put my file in the C: directory. Will little instructions that I can type up with pictures the user can easily put my one file in the C: directory. If you have any ideas of how I can keep the files that the .jar file creates that are linked to the excel spreadsheet without the user having to re-link the files no matter where the .jar file creates them let me know. If not, you helped out a lot, I got the .jar file to work and my program is now portable. All users will have windows OS so the .bat will work fine. For now. Thanks again.

    In case you don't know about linking txt files into excel. You can put data that is delimited by a comma for example and have it automatically upload to
    excel in real time as the data changes once its linked. This is MUCH BETTER to use when getting data from a serial COM port and putting data into excel then say using a DDE or some Keystroke repeater.

    my .bat file is:

    @echo off
    cd C:\AeroLead //which is the name of my file that users must put in the C: directory
    java -jar AeroLead.jar

    All my program does is takes a txt file filled with data that a machine spits out and creates files that can be linked into excel. Just a file manipulator.

    Any thoughts, comments, or suggestions? If so, send them my way!

    Thanks for letting me share my project. I'm excited about it.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: .jar Help

    Just a little thought while I read your post... This is a double post, and that's really a bit naughty. I have have left a link in the other thread pointing here which is the least we can do so that everyone knows what's happening.

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

    Default Re: .jar Help

    I copied posts from the other thread into this thread and wish to re-iterate what pbrockway states: please don't multipost the same question multiple times in the forum as it's not fair to the helpers here to unnecessarily divide the discussion. I've locked the other thread.

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: .jar Help

    If you have any ideas of how I can keep the files that the .jar file creates that are linked to the excel spreadsheet without the user having to re-link the files no matter where the .jar file creates them let me know.
    If I understand you correctly you have a process that will get what you want, so that's good. What remains is a sort of ugliness: that you are committed to using a specific directory set - by you - in advance.

    I didn't know about excel data sources. But I had a little play and found I could use a comma separated file and the spreadsheet would update (not "realtime", but every minute or when it was opened). But the problem seems to be that this file is known (to Excel) as an absolute path. I tried all the usual solutions to getting the spreadsheet to accept a relative path: google, reading the help files, sticking pins into a wax figure of BG.

    Nothing helped. You can put the jar whereever you like. You can put the spreadsheet whereever you like. But you must put the data text file at a specific location whose full path is hard coded into the spreadsheet. (Hence the logical thing to do is put all three into a common directory as you are doing.)

    This does seem to be an Excel thing. Others may know more about it and be able to suggest something.

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

    Default Re: .jar Help

    Quote Originally Posted by pbrockway2 View Post
    ...sticking pins into a wax figure of BG....
    Careful, please! I'm trying to see if I can somehow get my son to marry his oldest daughter!

  11. #11
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: .jar Help

    Quote Originally Posted by Fubarable View Post
    Careful, please! I'm trying to see if I can somehow get my son to marry his oldest daughter!
    Hardly inconsistent. Let me know when the happy event takes place and we can get to work with something more fatal than pins.

    (Good choice though: SJ disowned his oldest daughter. Really classy.)

Posting Permissions

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