Adblock breaks this site

Help Please

Discussion in 'Programming General' started by Draucia, Feb 10, 2010.

  1. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please

    I coded this Java program that opens with command prompt (no GUI or anything), and to run it, I open cmd and type

    "java C:\Users\xxxxxxxxxx\xxx.java".

    Is there someway that I can create a file (windows executable would be preferred), when clicked, will open that in cmd (or is there some other way to open it?).

    Please help me.
     
  2. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Help Please

    Open notepad. Paste that in. Save it has "run.bat"...
     
  3. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please

    It doesn't work. :(
    I put:
    java C:\Users\................\....
    and it doesn't work.
     
  4. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Help Please

    What error do you get?
     
  5. Molotov

    Molotov Active Member
    Banned

    Joined:
    Aug 26, 2009
    Posts:
    149
    Referrals:
    0
    Sythe Gold:
    0
    Help Please

    I've worked with java for a while, but I haven't made a executable file. Maybe save it as a .jar? or get a java compiler and maybe this should fix your problems.
     
  6. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please


    Well if I first type: cd [directry of .class file here], then type: java [file name], it works, but if I just type: java c:\users\xxxx\xxxx it doesn't work.
    I don't really need an .exe, just some way to open it without typing java then the class file name because other people who don't know much about java won't be able to do that. Do you know how I can get that into a jar file? I click export as a java jar, but it doesn't work when I double click.
    Oh and it's a console java application so it opens in command promt.

    I've tried saving it as a .jar, it doesn't work. And yes, I have a java compiler, thats how I compiled it into a .class file.
     
  7. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Help Please

    Just type "java NAMEOFJAVAAPPLICATION" in the batch file, and save it in the same directory as your Java file.
     
  8. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please

    Yeah thanks that worked, but is there some way I can package that into one file like a .jar file or maybe even .exe?
     
  9. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
  10. Molotov

    Molotov Active Member
    Banned

    Joined:
    Aug 26, 2009
    Posts:
    149
    Referrals:
    0
    Sythe Gold:
    0
    Help Please

    Ok, you can do it like a rsps private source. Just read the batch files in those.
     
  11. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Help Please

    And how do you think they do it..?

    @OP Why not just import your code into an IDE like Eclipse, or IntelliJ and have that export the jar for you (coding within an IDE really speeds up development time)?
     
  12. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Help Please

    ^That is your best bet.
     
  13. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please

    I don't really get that. There is one for class, which I have, and there is a option for main class or something. What is that going to be?

    Umm.. I don't really get it. o_O

    I made it in Eclipse, and when I export the .jar file and double click it, nothing happens. Did I mention this is a console application that opens in command prompt?

    Okay


    Thanks for taking the time to help me. :)
     
  14. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Help Please

    Oh, so the problem isn't that it doesn't run (it does run), but you don't see the output because the console isn't visible.

    Type:
    Code:
    @echo off
    java -jar JARNAME.jar
    pause
    
    And save it as run.bat in the same directory as your .jar file (change JARNAME.jar to the name of your jar, of course). Double click run.bat and it should run with the output visible. Then to update, simply replace the old jar with the new one.

    I do recommend, however, giving your application a GUI (Graphical User Interface) so that they can see the output in a nice window instead of in command prompt/terminal.
     
  15. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please

    Thanks, but isn't there some way I can package it into 1 file that I can send to someone. And also, I do not know how to make a GUI yet, I'm still learning. Or is it not hard and you can tell me now?
     
  16. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Help Please

    No. Because you're doing System.out.println()'s to show the user data, you must run it in terminal, so it has to be more then a single file.

    As for making a GUI, you should take a look at Sun's Swing Tutorials.
    http://java.sun.com/docs/books/tutorial/uiswing/
     
  17. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please


    Ok thanks, at least I got it working. I'll look at the tutorials, but I think my PDF tutorial will be better for me.


    EDIT: Ugh it says failed to load main class manifest.
     
  18. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Help Please

    When you're exporting the jar in eclipse, don't press the finish button as quickly as you can, press the next button until the final screen. On that screen, you must select the main class of the jar file (this is the class with your main method which will be called by the JVM to start your program). Once you do that, you can hit finish.
     
  19. Draucia

    Draucia Guest

    Referrals:
    0
    Help Please

    The "Next" button is disabled. What should I do?
     
  20. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Help Please

    Hit finish after you select the main class.
     
< Question | i need a mass email account creater >


 
 
Adblock breaks this site