Results 1 to 3 of 3

Thread: How to pass runtime arguments to JAVA Application

  1. #1
    Join Date
    Feb 2009
    Posts
    40

    How to pass runtime arguments to JAVA Application

    I have coded a simple multiple document viewing application. Up to this point, I've simply used a file chooser to open the files within my application.

    I recently added lines to the registry to allow for an application protocol url, similar to the "mailto: ". So now, I can type in the run window of the windows start menu: "myapp:file1.txt" and windows will launch my application and the file path will be passed through as a command line argument. (background info: i use launch4j to create an exe which in turn calls my jars, launching my application...)

    So the next step will be to create an association with a type of file, say *.txt, such that clicking on a txt file will launch my application.

    My ultimate goal is to be able to click on a second document in windows somewhere while my application is running and the doc will load in the same instance of my application... does anyone know how this would be accomplished??? I'm assuming that the initial file click, launching the application, will pass the file name in as a command line argument, but once the application is running, how would i get another command line argument into the application??? Is this possible in java??

  2. #2
    Join Date
    Jan 2006
    Posts
    211

    Re: How to pass runtime arguments to JAVA Application

    Like the following example you can pass the runtime argument to the JAVA application.

    Code:
    public class ArgumentPassingExample{
        public static void main(String[] args){
        int num=args.length;
        String s[]=new String[num];       
            if(num>0){
            System.out.println("The values enter at
     argument command line are:"); 
            for (int i = 0; i <num ; i++)
          {
          System.out.println("Argument " + (i + 1) + 
    " = " + args[i]);
          }
          }
          else{
            System.out.println("No values has been 
    entered at the command line.");
            }  
        }
    }

  3. #3
    Join Date
    Apr 2008
    Posts
    193

    Re: How to pass runtime arguments to JAVA Application

    The looking at this example configuration file, it appears that you need to set the wrapper.java.mainclass property.

Similar Threads

  1. Input and output arguments in java
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 09-03-2010, 12:32 PM
  2. Command Line Arguments in java
    By Vipul03 in forum Software Development
    Replies: 2
    Last Post: 22-02-2010, 04:39 PM
  3. What are Command-Line Arguments in Java?
    By Beter 2 Burn Out in forum Software Development
    Replies: 8
    Last Post: 20-02-2010, 03:37 PM
  4. How to pass arguments to the main method
    By Wannabe in forum Software Development
    Replies: 3
    Last Post: 12-09-2009, 11:51 AM
  5. Replies: 4
    Last Post: 25-02-2009, 07:15 PM

Tags for this Thread

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
  •  
Page generated in 1,714,094,742.88751 seconds with 16 queries