Page 1 of 2 12 LastLast
Results 1 to 20 of 34
  1. #1
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default Convert .java into a program i.e. .exe file

    hello as mentioned above, I was wondering if I could convert my .java file into a program that can be used by any computer, and run it directly instead of using netbeans to run it.

    I have searched online and the use of JNI's seems to be one solution which I have no experience in, is there a simpler way i.e. by using a software to convert a .java to .exe?

    Cheers

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    use IExpress.exe, it comes with Windows. just type iexpress in your start bar search.

    add your executable JAR file to the list.

    as the command to "install" the program, just copy the code you'd usually put in your BAT file.
    e.g. java -jar "myJar.jar"
    Last edited by ozzyman; 03-27-2011 at 04:02 PM.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Also read this thread; believe me, you don't want to convert .jar files to .exe files.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    Thanks Ozzyman, havent tried it yet but Ive found it

    Thanks JosAH, I have read the posts, how come its not advisable. All I need is something that I can take to another computer and run my program without going through cmd, netbeans etc etc.

    Is there a shorter way or better way than converting it to a .exe file

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ravi1 View Post
    Thanks JosAH, I have read the posts, how come its not advisable. All I need is something that I can take to another computer and run my program without going through cmd, netbeans etc etc.

    Is there a shorter way or better way than converting it to a .exe file
    If you take your .exe file to one of my Linux boxes, or worse, my old Solaris pizza box, I'm sure it won't run. If you'd take an executable .jar file to one of those boxes, it'd run on all of them. You don't need Netbeans to run your compiled Java code; all you need is an executable .jar file and an installed JRE.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    Thanks for that Jos, I have converted the file into a jar.


    When I run the jar, it asks me which program I want to open the file with, what am I to do?

    Can I now use this file on any computer?

    can this file be run without any prerequisite i.e. without any jdk or jre installed.

    Apologises for any dumb questions asked?


    Regards

  7. #7
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    you need to run the JAR file through command prompt. to save your user from doing this, kindly write them a BAT file which contains the code. if your only target is Windows based system, it wouldn't harm to go ahead with making an EXE with iexpress

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ravi1 View Post
    Thanks for that Jos, I have converted the file into a jar.


    When I run the jar, it asks me which program I want to open the file with, what am I to do?

    Can I now use this file on any computer?

    can this file be run without any prerequisite i.e. without any jdk or jre installed.

    Apologises for any dumb questions asked?
    Carefully reread my previous reply; of course you need to have the JRE installed because that's where the JVM is stored. You also need to fix your file associations (I don't know how to do that on a MS Windows box).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    to edit the file associations in windows, right-click the file, click Properties, you'll see something that says Opens with: ... [Change].

    Click change to change it, but be WARNED do NOT change EXE, DLL or other system file extentions

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

    Default

    Quote Originally Posted by ozzyman View Post
    you need to run the JAR file through command prompt. to save your user from doing this, kindly write them a BAT file which contains the code. if your only target is Windows based system, it wouldn't harm to go ahead with making an EXE with iexpress
    I'm not sure that IExpress is doing what you think it's doing. It's certainly not converting a Jar file into an exe file. Yes, it may be creating an exe file, but it is not a conversion of the Jar, rather it creates a self-extracting file from the JAR. Files created from this still need the jre to run.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ozzyman View Post
    you need to run the JAR file through command prompt. to save your user from doing this, kindly write them a BAT file which contains the code. if your only target is Windows based system, it wouldn't harm to go ahead with making an EXE with iexpress
    You don't need a .bat file if the users aren't ignorant script kiddies that ruin their registry regularly, the file associations are set properly by the installation program.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Fubarable, while I realised that I think thats all the asker wanted - convenience for the user

    Jos, since i installed Java the file extensions for JAR files were never set to run with java. i now changed it to java.exe and it doesn't work that way? what is it supposed to run with?

  13. #13
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Actually i just found this freeware to do it for me:
    JarFix.exe will automatically set JAR file extension to open correctly
    Jarfix

  14. #14
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    Thanks for all the replies. I tried running the jar file and what I got was could not find main file, I put both the main file and the jar file in the same folder, those are the only 2 files there, do I need any more files in the folder?

    Regards

  15. #15
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    ravi use jarfix.exe, then you can simply double-click the executable JAR file to run it

  16. #16
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    Thanks for that, I have installed it and will try it in a mo.

    What about me using iexpress, when I try and add the files it shows an error that there is no main file, do yu know why?

    regrads

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ravi1 View Post
    Thanks for all the replies. I tried running the jar file and what I got was could not find main file, I put both the main file and the jar file in the same folder, those are the only 2 files there, do I need any more files in the folder?
    Did you define a manifest entry for that .jar file or did you just stick all your .class files in your .jar file; in that case all you have is a .zip file with .class files in it. How is the JVM to know which of those .class files contains the main( ... ) method it should run?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  18. #18
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    i used the following to create the .jar file

    Creating a jar File in Command Prompt

    1. Start Command Prompt.
    2. Navigate to the folder that holds your class files:

    C:\>cd \mywork

    3. Set path to include JDK’s bin. For example:

    C:\mywork> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%

    4. Compile your class(es):

    C:\mywork> javac *.java

    5. Create a manifest file:

    C:\mywork> echo Main-Class: DanceStudio >manifest.txt

    6. Create a jar file:

    C:\mywork> jar cvfm DanceStudio.jar manifest.txt *.class

    7. Test your jar:

    C:\mywork> DanceStudio.jar

  19. #19
    ravi1 is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    In the above post, it shows that I created a manifest file and also the jar file, should I add the 2 in iexpress, I tried that and still the error is shown.

    any suggestions?

    Regards

  20. #20
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default all senior members

    If this is okay,then you can use this for the next posts related coverting .jar to .exe

    উজ্জ্বল সূত্র ধর: Converting .jar to .exe

Page 1 of 2 12 LastLast

Similar Threads

  1. Convert Java program to web-app
    By carderne in forum New To Java
    Replies: 3
    Last Post: 12-08-2010, 07:10 PM
  2. Convert XML file into DTD using Java
    By veera in forum XML
    Replies: 0
    Last Post: 12-19-2008, 06:38 AM
  3. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 10:57 AM
  4. Replies: 1
    Last Post: 07-02-2008, 02:58 PM
  5. Convert a program to Applet
    By carl in forum Java Applets
    Replies: 2
    Last Post: 08-09-2007, 10:33 PM

Posting Permissions

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