SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Run a java file directly in Windows

    Hi everyone! Once I read from a sitepointer,
    Code:
    Instead of executing the command directly, use this instead:
    Code:
    String[] cmd = new String[3];
    
    cmd[0] = "cmd.exe";
    cmd[1] = "/C";
    cmd[2] = theInput;
    You need to hit the windows command interpeter first or you won't be able to do much.
    theInput is your command.
    I would like to run a java file directly [not using cmd] by clicking on a simple icon or button.
    Could anyone provide some help.
    -1/2=999?

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure I understand your question. By "java file" do you mean a Java class file or a JAR file?

    You can create a shortcut in Windows that points to javaw.exe (in your Java Runtime Environment directory) and passes the necessary arguments to launch your class or JAR file.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kevin
    passes the necessary arguments to launch your class or JAR file.
    Could you please tell me more of that. Tnks for your reply kevin.
    -1/2=999?

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    For example, I have a Windows shortcut that launches jEdit, a text editor written in Java that is packaged in a JAR file. Here's the target of that shortcut:

    "C:\Program Files\Java\jdk1.6.0\bin\javaw.exe" -jar "E:\Program Files\jEdit\jedit.jar"

    In addition, the working directory of the shortcut should be set to the directory where the program's other files (if any) are located.

    If you want to launch a class instead of a JAR file, just omit the -jar argument:

    "C:\Program Files\Java\jdk1.6.0\bin\javaw.exe" com.example.MyMainClass
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Kevin, let me ask some few more question.

    First, what if I use java.exe instead of javaw.exe, how do really make difference?

    Second,
    "C:\Program Files\Java\jdk1.6.0\bin\javaw.exe" com.example.MyMainClass
    will run the class file, am I right?
    -1/2=999?

  6. #6
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IIRC javaw will not leave a shell window open.

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Correct. The benefit of javaw.exe is that no console window is displayed. If you need to see messages that appear in the console, however, use java.exe to get that console window.

    Yes, Borna, assuming you have Java installing in C:\Program Files\Java\jdk1.6.0, then that command will run the class file com\example\MyMainClass.class from the current directory.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

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