Results 1 to 12 of 12
  1. #1
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default Executing JAR File by double clicking

    Hai,

    I created one program using NetBeans.

    To use NetBeans, there is no need set the class path.

    DataBase connectivity, we just add the DBConnection jar file for that.

    NetBeans itself create the JAR file for our program. If i put that Project jar file, in any other system,
    Is it possible to run the program, by double clicking it?

    Thanks in advance.

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    You need to create an executable jar. To do this manually, you create a manifest file. Create a file called, say, manifest.txt that contains a line such as:

    Main-Class: com.mypackage.MyMainClass

    then when you package up your Jar, you add an -m switch to the jar command, giving the name of the manifest file.

    I'm guessing NetBeans has some friendlier way to ad a "manifest file", but that's probably what you're looking for.

    Now, whether a particular system decides to launch the jar when a user double-clicked on it is system-dependent. It works on Windows, though, which covers most of the user base not used to using a command line.

  3. #3
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Thanks for your reply,

    If i double that jar file, it is opening the interface. But DB connection is not working, through this.

    But if i execute the project, through NetBeans.. It is working fine.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    NetBeans does all of this by itself, automatically, per default. Including the classpath references to the external jars and places those jars in a lib directory that sits in the same directory as the original jar so everything is ready to be packed up and deployed by simply taking the entire "dist" directory.

    But you have take the entire contents of the "dist" directory, not just the application jarfile.

  5. #5
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Thanks for your reply...

    Its perfectly working in some system , if i put that dist folder.

    Some machine, if i double click , no action is happening....

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Well, "no action is happening", doesn't help, to tell you the truth.

    Open a command prompt and type

    Java Code:
    java -jar /full/path/to/jarfile.jar

  7. #7
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    It is working in Command prompt.

    If i double click that jar file, it is not working..

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Then what do you mean by "some systems"? By specific OSes (I.E. Solaris/Windows) or by specific computers even though it is the same OS?

    In any case, if it "works" on that system from the command line, then the problem is not (at least not solely) Java related, but is rather system related. Either faulty file associations or some other system item, but no longer, per se, a Java problem.

  9. #9
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Window os only.

    All systems are Windows xp.

    Help me to debug this kind of issue....

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Well, as long as you file associations are set properly (and the user doing the "clicking" has access to the jarfile) then "double-clicking" that jarfile does exactly what you did in the command line. All you can do is to check your file associations and file access permissions.

  11. #11
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Thanks for your reply,

    I dont know, how to check file associations and file access permissions?

    Can you assist me?

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

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 jar double-click style in Linux
    By goodwillwins in forum AWT / Swing
    Replies: 24
    Last Post: 03-19-2011, 04:56 AM
  3. Double clicking executables jar files?
    By cruxblack in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 02:00 AM
  4. [SOLVED] Error executing Jar file
    By VeasMKII in forum New To Java
    Replies: 3
    Last Post: 01-31-2009, 05:32 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
  •