Page 1 of 4 123 ... Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    101
    Rep Power
    0

    How do you convert a .java to a .exe file?


    I been making GUIs in java and I love it. But obviously when I double click the .java file the compiler opens up. I know I can run it in the command prompt, but I'd rather setup a desktop icon so I can double-click and open.

    I'm guessing I need to download a different program other than a compiler, right?

    If this is a compiler question I apologize, though the compiler I use is jGRASP. I looked through their help files and only seem to find information on running/compiling it, not converting it to a .exe file.

    Thanks.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Normally java class files are packaged in a jar file which can be executed on many different OS.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    101
    Rep Power
    0
    Okay I think my compiler does have the jar feature, I just have to select the .class file rather than the .java, and it would only be 1.

    But my issue isn't executing it. My issue is changing it to a .exe file so I can open it by mouse-click rather than opening it by opening a compiler 1st or going to a command prompt.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    I execute jar files by double clicking on them. The JRE installation should establish that connection and mechanism.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    101
    Rep Power
    0
    Okay damn, my next question is how do I convert to a .jar file.

    In my compiler, I see there's a "Jar / Zip extractor"

    I can "File, Open Jar or Zip file"

    I don't see 1 to begin with.

    There is a "Create Jar or Zip file for project" but it is not clickable.

    It was clickable when I had a bunch of multiple files open, but I closed them all, because what I want executed is 1 file only. I'm guessing I can't if I only want to build 1 file?

    Thanks.
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    There should not be a problem creating a jar file with only one class file in it.
    I use the jar command in a batch file to create my jar files. No IDE involved.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    101
    Rep Power
    0
    Meh, do I convert the .java file or the .class file into the .jar file?

    Does it have to be a project? Or in a project?
  14. #8
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    A jar file is like a zip file, it contains other files. The jar command is used to create the jar file and to put other files, like class files, into the jar file.

    If you are using an IDE there may be a project involved. I don't use an IDE and don't know what they require.

    If you are using an IDE you need to read its doc to see how to use it to create a jar file.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    101
    Rep Power
    0
    To do this without the compiler, I'd ask what the jar syntax is (like jar class1 class2 file.jar), but my command prompt doesn't recognize jar as a command.

    As with the compiler, I'll look into that.

    Thanks.

    I guess I should be coding GUIs in C++. I guess most .exe's are coded in C++.
  18. #10
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    The jar command is in the SDK's bin folder with the javac command.
  20. #11
  21. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,739
    Rep Power
    1959
    FWIW, I think a clarification is in place with all those terminologies flying around, some more correct than others. Hope it is useful "as is"

    jGRASP
    This is what we call an IDE which is a mainly a code editor with a more easier/direct/integrated access to the compiler. It can also contain several other kind of functionalities.

    compiler / JDK
    Java SDK (aka JDK) is the "development kit" which contains the tools (among others) to compile Java files into class files as well as placing classes into a Jar file.
    - To compile source code files with the command line you will use the program "javac".
    - To "collect" classes into a jar file, you will call the program "jar" (also by using the command line).

    JRE
    This is the Java Runtime Execution having the program "java" which is used to run the class and/or jar files.
    It is also part of the JDK installation.

    Originally Posted by LostShadow
    I guess I should be coding GUIs in C++. I guess most .exe's are coded in C++.
    It is possible to make GUI with C++, although this language can be a bit harder to learn.

    C# (.NET) also makes exe files and can feel more similar to Java. Just note that to run this kind of program it requires the .NET Framework to be installed on the computer

    Comments on this post

    • NormR agrees : Nice post.
    • Nilpo agrees
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    101
    Rep Power
    0
    Originally Posted by NormR
    No IDE involved.
    Okay, my next question would be how to convert it to a .jar file without using an IDE since that's what the people here specialize in.

    And earlier.
    Originally Posted by NormR
    I execute jar files by double clicking on them. The JRE installation should establish that connection and mechanism.
    I guess I need to download a JRE then. I just recall downloading a Java SE to go with the jGRASP IDE.
  24. #13
  25. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    The jar command is documented here:http://docs.oracle.com/javase/7/docs...jar/index.html
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    101
    Rep Power
    0
    Where do I use the jar command, in the command prompt? In the java file?

    I don't have Oracle, but I do have Microsoft Access, do I download Oracle?

    The jar command is documented here:http://docs.oracle.com/javase/7/doc.../jar/index.html
    I see the java.util.jar package, so that makes me think I have to have that in the code.

    http://docs.oracle.com/javase/tutorial/deployment/jar/build.html This page talks about the jar command and I think it's referring to a place like the command prompt.

    Prior to downloading Java SE, I could not use javac in the command prompt, nor could I build or compile in the IDE.

    I had to download Java SE, and surprisingly, I could still not use the javac command (but the java command works), but I could build or compile.

    Of course if I can't javac in the command prompt I have other issues, but I'd like to be able to use the jar command also.

    However, I presume the Java SE I downloaded included the java.util.jar package or library so I might be having some registry issues. I'm using Windows 7.
  28. #15
  29. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    The javac and jar commands come with the java SDK.

    Where do I use the jar command, in the command prompt
    Yes or in a batch file.

    do I download Oracle?
    You need the java SDK
Page 1 of 4 123 ... Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo