Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: How do you make a console program a .jar in Eclipse?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    My Mood
    Bored
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How do you make a console program a .jar in Eclipse?

    I've been making console programs for some time now,
    And I use Eclipse.
    But I've never made a single console program a .jar before.
    I've read other threads and some tutorials,but then when I export it, I cant see the console or the console isn't opening at all.
    I've heard that you need some batch file to do it, or use the command prompt,but I don't know what to do.
    All I need is that there to be an icon. Double click the icon,a command prompt pops up and runs a program.
    Any help will be greatly appreciated.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do you make a console program a .jar in Eclipse?

    Well, what you've heard is correct- you either need to open the jar on the command prompt, or you need to write a script that opens the command prompt and runs the jar for you. The jar can't open the command prompt and run itself.

    You could also google something like "java open command prompt" and write a program that opens the jar this way, but it's the same principle.
    Last edited by KevinWorkman; January 9th, 2012 at 11:44 AM.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: How do you make a console program a .jar in Eclipse?

    Double click the icon,a command prompt pops up and runs a program.
    uhm.. is it something like a VB script? Inside the forum, on the snippets and Tutorial Threads, i got a very wonderful code, when you run it, a JOptionPane dialog will pop up, asking you if you want to open your CD-ROM, when you press OK, it will open(only a problem with closing), it has some VB script something, i'm not sure if its a bit relevant to what you are looking at

    look at here, i found it
    http://www.javaprogrammingforums.com...dvd-drive.html

    although the code is all about CD drive, it has something to do with computer system command things, i hope this can guide you to what you need
    Last edited by chronoz13; January 9th, 2012 at 12:10 PM.

  4. #4
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: How do you make a console program a .jar in Eclipse?

    -.- , you made me curious , i got this on web.

    Runtime.getRuntime().exec("cmd.exe /c start");

    now you just have to work on your .jar .. -.-

  5. #5
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: How do you make a console program a .jar in Eclipse?

    If you are using windows a simple batch script will do it. Create a text file in the place you want to run it from. The command is exactly what you would use to run the jar file from the command prompt. Finally, rename it to run.bat

    @echo off
     
    java -jar path/to/jar_file/myJarFile.jar

  6. The Following 2 Users Say Thank You to ChristopherLowe For This Useful Post:

    KevinWorkman (January 10th, 2012), Programmer142 (January 12th, 2012)

  7. #6
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: How do you make a console program a .jar in Eclipse?

    double post

  8. #7
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    My Mood
    Bored
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How do you make a console program a .jar in Eclipse?

    Reply to Christopher: Thank you! However,when I run the .bat,it says something about "sun.lang" and I think I saw a "Launcher" in there somewhere...maybe even a "getMainClass"? Yes,I have set the proper location. ....but the program is in C:/ .... My system doesent want me to go snooping around there,maybe my system is blocking java from getting acess?

  9. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do you make a console program a .jar in Eclipse?

    Quote Originally Posted by Programmer142 View Post
    Reply to Christopher: Thank you! However,when I run the .bat,it says something about "sun.lang" and I think I saw a "Launcher" in there somewhere...maybe even a "getMainClass"? Yes,I have set the proper location. ....but the program is in C:/ .... My system doesent want me to go snooping around there,maybe my system is blocking java from getting acess?
    If you want help, you'll have to post the actual error message here. We can't really guess from vague descriptions like that.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #9
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: How do you make a console program a .jar in Eclipse?

    If you have trouble reading the error messages run the bat file from the command line rather than double clicking on an icon.

  11. #10
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: How do you make a console program a .jar in Eclipse?

    Quote Originally Posted by Programmer142 View Post
    Reply to Christopher: Thank you! However,when I run the .bat,it says something about "sun.lang" and I think I saw a "Launcher" in there somewhere...maybe even a "getMainClass"? Yes,I have set the proper location. ....but the program is in C:/ .... My system doesent want me to go snooping around there,maybe my system is blocking java from getting acess?
    Perhaps.. There are several things that can cause this. Can you run the program from the command line at all? Can you run the java command? The batch script is just a shortcut so, like regular shortcuts it will not work if it can't find what is pointing to.

    Try this at the command prompt:

    javac -version

    If it says that it cannot find javac then you need to configure your PATH environmental variable to include the SDK's bin directory.


    Actually, I just remembered I wrote a batch script many many years ago to check out if your system is configured correctly. Miracle I still have it. This should make things easier:

    @echo off
    echo You path is:   
    echo %PATH%
    echo .
    echo Your JRE is:
    java -version
    echo .
    echo Your Java compiler version is:
    javac -version
    echo .
    echo Your ant version is:
    ant.bat -version
    echo Your GIT version is:
    git --version
    echo .....................
    set /P theuserinput="Press [ENTER] to finish"

    At the least, you need java and javac working.

    Oh, and you can add that last line to the end of your run.bat script and it will give you a chance to see the error message you are getting.

    Let us know how you get on.

Similar Threads

  1. How to make Eclipse work with txt file?
    By Prostak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 4th, 2011, 05:43 PM
  2. Replies: 3
    Last Post: September 19th, 2011, 03:42 AM
  3. How to make a program into a working .jar? (eclipse)
    By ynnad95 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2011, 08:29 PM
  4. simple java console program, need help recalling commands
    By zero0000000 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 22nd, 2010, 05:47 AM
  5. Unable to redirect all the eclipse console logs to buffer
    By skrishnapradeep in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 23rd, 2010, 11:03 PM