Results 1 to 9 of 9
  1. #1
    pradnya is offline Member
    Join Date
    Jun 2008
    Posts
    12
    Rep Power
    0

    Default How to create .exe file using .class file

    Hi,

    Could anybody help me to give information that how to create a .exe file using .class file ?
    Few developers told me about some tools. But is it necessary to hose tools ?

    Thanks,
    Pradnya.

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    I am not 100% sure if it is necessary to use tools to create .exe files from your classes... But I use Null Softs NSIS and their NH NIS Edit... NH NIS Edit has a great wizard that makes things nice and easy...

    I hope no body considers this as promoting software... Because I have asked this question many times (Before I joined here) and nobody was ever able to give me an answer...
    Who Cares... As Long As It Works...

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Are you trying to convert the class file to a native binary, or simply make it runnable by double clicking on it?

    If you're just trying to make it executable, create an executable jar file from it, by first creating a manifest file, andt then using the jar command.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    pradnya is offline Member
    Join Date
    Jun 2008
    Posts
    12
    Rep Power
    0

    Default

    HI,

    I am trying to make it runnable..
    My intension is to make .exe file of my project so that I can copy on CD and run directly on Client machinerather to copy everything.
    like if we see in software CD, we have setup.exe file, once it is click, program starts.
    I want to do follow the same ..
    Please help me out.

    Thanks,
    Pradnya.


    Quote Originally Posted by toadaly View Post
    Are you trying to convert the class file to a native binary, or simply make it runnable by double clicking on it?

    If you're just trying to make it executable, create an executable jar file from it, by first creating a manifest file, andt then using the jar command.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  7. #7
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    My intension is to make .exe file of my project so that I can copy on CD and run directly on Client machinerather to copy everything.
    like if we see in software CD, we have setup.exe file, once it is click, program starts.

    No Prob...

    The first time i tried to do this it took me a couple of LONG hours... So dont get fustrated... The best thing to do is to make a VERY simple java app and get it to work as an .exe... Then get your final app to work...

    Unfortunately I just updated my computer to Fedora 10 and I forgot to backup my scripts to do what you want, but I did find a very simple one that is not the best but it works...

    First thing that you will need to do is download NullSofts NSIS and NH NIS Edit

    The next thing you will have to do is make sure that if you are using any external files (icons, images, text files to read from, etc.), that the path in your program points to your Program Files on your computer... On my windows computer it is:C:\Program Files... I am not a avid windows user so I am not sure it this is the same for Vista...

    After this, you will need to complie your project into a jar... And test it... make sure that it works by double clicking it on the windows computer... If it doesnt work then you will have to fix it...

    Now copy this script to a .nsi file:

    Java Code:
    ; Java Launcher
    ;--------------
     
    
    Caption "Java Launcher"
    
    OutFile "MyJavaApp.exe"
     
    SilentInstall silent
    AutoCloseWindow true
    ShowInstDetails nevershow
     
    ;You want to change the next two lines too
    ;You want to change the next two lines too
    !define CLASSPATH "path/to/YourJar.jar"
    !define CLASS "path/to/your/YourMainClass.Main"
    
     
    Section ""
      Call GetJRE
      Pop $R0
     
      ; change for your purpose (-jar etc.)
      StrCpy $0 '"$R0" -classpath "${CLASSPATH}" ${CLASS}'
     
      SetOutPath $EXEDIR
      Exec $0
    SectionEnd
     
    Function GetJRE
    ;
    ;  returns the full path of a valid java.exe
    ;  looks in:
    ;  1 - .\jre directory (JRE Installed with application)
    ;  2 - JAVA_HOME environment variable
    ;  3 - the registry
    ;  4 - hopes it is in current dir or PATH
     
      Push $R0
      Push $R1
     
      ; use javaw.exe to avoid dosbox.
      ; use java.exe to keep stdout/stderr
      !define JAVAEXE "javaw.exe"
     
      ClearErrors
      StrCpy $R0 "$EXEDIR\jre\bin\${JAVAEXE}"
      IfFileExists $R0 JreFound  ;; 1) found it locally
      StrCpy $R0 ""
     
      ClearErrors
      ReadEnvStr $R0 "JAVA_HOME"
      StrCpy $R0 "$R0\bin\${JAVAEXE}"
      IfErrors 0 JreFound  ;; 2) found it in JAVA_HOME
     
      ClearErrors
      ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
      ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
      StrCpy $R0 "$R0\bin\${JAVAEXE}"
     
      IfErrors 0 JreFound  ;; 3) found it in the registry
      StrCpy $R0 "${JAVAEXE}"  ;; 4) wishing you good luck
     
     JreFound:
      Pop $R1
      Exch $R0
    FunctionEnd

    Now this will create an .exe that will trigger your jar... When you make your setup.exe you will still need both of these...


    Now test it... Make sure this works...

    You will need to create a license... It can be anything you want and save it as a text file...

    Once you get this working open NH NIS Edit and go to File>New Script From Wizard...

    Once you get here follow the Wizard instructions...

    If you get stuck, let me know...


    Also... When you do installers you are supposed to test to see if the client computer has java and the jre... Neither of these scripts do this, so you will have to make sure that the client computer has java and is up to date...
    Who Cares... As Long As It Works...

  8. #8
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    An executable jar file is portable like an .exe to any system with a java runtime installed.

    It's trivial to create one with a simple manifest file and a jar command. Suppose all your java files were in one directory and you are not using packages. First, just build everything the way you normally do. Then, create a manifest file. For the sake of this example, let's just call it "manifest". Suppose your main class is called Main, and you want the jat file to be called main.jar. The manifest contents would look something like:

    Java Code:
    Manifest-Version: 1.0
    Main-Class: Main
    Class-Path: .:./main.jar
    Then, to create the executable jar, open a terminal window somewhere and make sure teh JDK is in your path, and execute:

    Java Code:
    jar cmf manifest main.jar *.class
    That's it. You can now double click on 'main.jar' to launch your application, and you can easily just copy to another system somewhere.

    If you are using resource files, such as icons or sound files, you just include those subdirectories in your jar command, and use either the Class or ClassLoader to load them for you.

  9. #9
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If you want an installer then use a standard installer tool to copy across the jar file(s) and make a shortcut to
    Java Code:
    javaw -jar main.jar
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. How to create a file
    By Alpha in forum New To Java
    Replies: 7
    Last Post: 01-06-2012, 08:10 PM
  2. how to create jar file ???
    By doha786 in forum New To Java
    Replies: 2
    Last Post: 04-13-2009, 08:50 PM
  3. .class file to .java file
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 02-20-2009, 07:46 PM
  4. Convert my class file into a exe file
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 09:35 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
  •