Include command line args in executable jar?

Hello all,
I'm trying to package up some software which takes 2 command line args to run (for example, java -jar prog.jar FooBar 3.14159). I'm using a utility called Jar2Exe to wrap it up into an exe (still needs JRE to run, but it's nicer packaging for distribution).
My question is, how can I included command line arguments in the jar? Or can I? Or, are there any exe-wrapping utilities out there that will allow me to accomplish this?
Thanks,
-Thok

Thok wrote:
Hello all,
I'm trying to package up some software which takes 2 command line args to run (for example, java -jar prog.jar FooBar 3.14159). I'm using a utility called Jar2Exe to wrap it up into an exe (still needs JRE to run, but it's nicer packaging for distribution).
My question is, how can I included command line arguments in the jar? Or can I? Or, are there any exe-wrapping utilities out there that will allow me to accomplish this?
Thanks,
-ThokOkay, did some more research... It appears you can't specify command line options in a jar, but if you package it into an exe, you can--depending on what utility you use to wrap it, that is. I downloaded a free one (Launch4j) and it does the trick.
-Thok

Similar Messages

  • Include command line args in jar file

    If I make and executable jar file, how can I make it so that when it runs certain comman line arguments are included

    If by "executable jar" you mean that you want to click the jar and run the program (and are using Windows), then you would have to alter the Windows file association for jar files that Java created, adding those options to the javaw command. Note that that would affect all jars that are run this was.
    If you're willing to use the "javaw -jar" command, then just add the options to the javaw command.

  • Command line options in executable jar

    Hello,
    On a win32 system I have an executable jar that the user dbl clicks to run.
    What I would like to do is maintain this simple dbl click to run but have command line options passed to the vm. ie I would like the dbl click to invoke
    javaw -Xms60m -Xmx120m -jar myjarfile.jar
    rather than just
    javaw -jar myjarfile.jar
    Can these options be placed in the jar files manifest? If so how? (I can't see how to do it)
    Many thanks
    Mike

    why not use special .jar tool to help you to save much
    of your time?
    Thanks for the idea but it really doesn't answer my question.
    Mike
    [Edited by: jdcforumadmin1 on Jun 24, 2002 1:39 PM]

  • Wrong to process command line args in a loop?

    I tried to process my command line args like this:
    int[] rgb = {0,0,0};
              for(int i=1;i<3;i++)
                   rgb[i-1] = Integer.parseInt(args);
    I enter six args where args 1 to 3 are ints and not zero, but rgb[2] always ends up being zero. I had to do away with the loop and write out three assignment statements, but if I had ten or more args that would be a headache! Does anyone know why this is happening? I'm using JDK 1.3.1_15.

    for(int i=0;i<3;i++)
       rgb[i] = Integer.parseInt(args);
    Look closely and make sure you understand the differences between my code and yours:
    * i starts at 0, not 1
    * rgb uses i for index, not i - 1.
    Why would you have rgb using i -1 and args using i?
    Now, if you have an arg [i]before the RGB args, then it would make sense for args' index to be different than rgb's. In that case, you might have i-1 and i, or i and i+1, etc. depending on how you structure your loop.
    The main problem is that you had i=1; i<3, which will go through the loop body for i=1 and i=2 only. Make sure you understand why.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Command line args

    I have this program and I need to use command line args which
    will print ell . this program does this but I am using
    substring instead of command line args.
    public class h11 {
    public static void main (String [] args ) {
    String greeting = "Hello";
    String h11 = greeting . substring (1, 4);
    System.out.println( h11);
    output: ell
    Anyone..

    First off, the index of characters in a String is 0 based so in the string "Hello" you have the following;
    char 0 = "H"
    char 1 = "e"
    char 2 = "l"
    char 3 = "l"
    char 4 = "o"
    String.substring(start, end) is first inclusive and last exclusive so the parameters (1, 4) would return characters 1, 2 & 3 but not 0 or 4.
    To get the whole word Hello (not withstanding that that's the entire string) you would want greeting.substring(0,5) however that would generate an index out of bounds error because 5 isn't a valid index for that string. So, here's a small sample program to show how to do what I think you're after.
    public class ParmsTest{
         public static void main(String[] args){
              if( args.length > 0 ){
                   String parm = null ;
                   int end = 0 ;
                   int start = 0 ;
                   for( int i=0; i< args.length; i++ ){
                        parm = args[i] ;
                        if( parm.length() > 4 ){
                             end = 4;
                        else{
                             end = parm.length() - 1 ;
                        if( end > start ){
                             System.out.println( parm.substring(start, end) ) ;
                        else{
                             System.out.println( "Nothing to get" ) ;
              System.out.println( "Finished processing parameters" ) ;
    }It's a bit more complicated than your sample, but it also checks to see if there were any parameters, and it checks to see if the length we're trying to get is valid. Lastly it checks to see if there was anything to get before trying to print it. If it doesn't find anything to print it prints a message saying so.
    Here's the question I have for you. Why? Why did I go to this trouble?

  • Bash number of command line args....

    Hi,
    Is there a way in bash to get number of command line args ...
    atm I am using $1 but of course if you pass a command like uname -a you need two?
    wondered if there is a $<foo> that ill give number of args passed?
    EDIT looks like '$#' emmmm lets see....

    woah!!! ok thanks ..... $# gives me number of args ... will check it out
    $1 $2 > /tmp/cmd
    messy way.....

  • JAVA command line options -cp and -jar don't work together?

    Running JSDK 1.4.2 under Windows. I have a Java application that tries to dynamically load a class name that the user enters as follows:
    try {
    classResult = java.lang.Class.forName(strFilterName);
    catch (ExceptionInInitializerError e) {
    strErrorMessage = "ExceptionInInitializerError loading class: " + strFilterName;
    catch (LinkageError e) {
    strErrorMessage = "LinkageError loading class: " + strFilterName;
    catch (ClassNotFoundException e) {
    strErrorMessage = "ClassNotFoundException loading class: " + strFilterName;
    This works fine if the classes that make up my application are left as class files in the classpath, but fails to work if they have been collected and run from a JAR file. Note: I can even dynamically load the class when running from the JAR file, if the class I'm trying to load is within that JAR file too. The problem really occurrs when the dynamically loaded class is located someplace else in my classpath. I've tried using various combinations of the "-cp" and "-jar" Java command line options - but when loading and running from a JAR file - the "-cp" parameters seem to be ignored. Is this a bug? Has anyone ever seen this before?
    I run my program from the JAR file using this command:
    java -cp .;e:\entmgr\filters -jar EntMgr.jar
    Where "e:\entmgr\filters" is where the class I'm trying to dynamically load is. (This class has no package name, but loads perfectly as long as I'm not running the application from the JAR file). The class name specified by the user has to be fully specified with a package name (if it has one).
    I have tried forcing the "java.lang.Class.forName(strFilterName);" call to use the system class loader, the parent of the system class loaded, and even the null bootstrap class loader - all with no success.
    I am suspecting that the class loader that is loading and running my main program from the JAR file, is just not paying any attention to the "-cp" parameter when the "-jar" parameter is present. Indeed, I have never seen any change in the failure, no matter what I put in the "-cp" parameter when using the JAR file.
    When I run this without using the JAR file, here is the command I execute:
    java -cp .;davidp\snmp;filters davidp.snmp.EntMgr
    Where this is executed in a directory that has a "filters" and "davidp\snmp" directory. In this case, because the "filters" directory is in my class path - I can dynamically load my class from it using just its simple name (i.e. "TestTrapFilter").
    So, is there some bug that precludes the "-cp" parameter from working correctly when the "-jar" parameter is used? Is there some other way to initialize or set up the classloader I'm using, so it can find things outside of the JAR file I'm running from? I would hope that it is possible to get the same behavior from my program, no matter if it is run from a JAR file or not.
    Thanks for any assistence!
    Dave

    These posts are pretty old, but this page came up in a google search while I was having the same problem, so I thought I would throw my own (Later found) solution in.
    The -cp and -jar options did not work together for me, but I later learned that they didn't really have to (and you don't have to mess with jar manifest files).
    While on the command line, if you want to set a specific class path and also run a jar, all you need to do is add the jar to whatever extra class path you need to use in the -cp <arg>, and then specify which class you want run from inside the jar.
    IE:
    java -cp <YourSpecialClasspath>: <PathToJar> <ClassToRunInsideOfJar>
    in my case it was like:
    java -cp /home/user/WebRCP.jar:./StandaloneInstaller.jar InstallLoader
    Remember to put a ":" in between the two arguments for the class path (-cp).
    Hope this helps someone in the future,
    -Josh

  • Vm arg in executable jar

    Hi,
    I do this to run my java class (because it uses a lot of memory):
    java -Xmx128M Crossword
    and this works fine.
    Now I've made an executable jar to run my class just by double clicking on the jar file. The problem is that I dont know how to make the jar use this VM parameter. I dont want anything external to my jar to have to change. I want to just be able to drop my jar on a different PC (with a JRE installed on it of course) and be able to run the jar just be double clicking it.
    Anyone know how to do this?
    Thanks,
    Jim

    There are of course other solutions.
    For example you write a simple application that starts a VM using Runtime.exec(). That is OS specific (and requires some work for each system.) It exits once it starts the other VM.
    You could even wrap it in a single jar by having passing in a command line parameter that specifies "run real' or 'start with correct memory'.
    I believe one of the properties in System.getProperites() has the VM path.

  • Main-args in executable Jar file. Possible?

    Hello all!
    Is it possible to specify arguments for the main class of an executable jar file?
    If you call it on the command line this might be possible but what to do if you start the jar with double click?
    Any chance?

    i don't think so, see http://java.sun.com/docs/books/tutorial/jar/basics/mod.html

  • Command line wasn't executed in ftp adapter

    Hi,gurus:
        I met a problem when I used "Run operating system command before message processing" in a file to file scenario.After the message was processed successfully I found the command wasn't executed.However,the command(bat file) could be executed in XI server.
       The value of the parameter "command line" is  "c:\data\copyResult.bat %F %f".I want to use the bat file to delete the archived file after the message is processed successfully.But now it was not executed.The content of relavant file is below.Any ideas?Any help will be appreciated.
      ( Also I have referred to michal's blog about error catching,but it didn't work.)
    copyResult.bat
    ftp -s:copyResult.txt
    copyResult.txt
    open <ftp_host>
    <username>
    <password>
    cd /archive
    delete send.txt
    quit

    Hi,
    Have you tried to check the execution of BAT file directly on FTP server or may be you are trying with XI server. What are the results for it.
    Plesae check the log of each and every step ...in Runtime Worbench in Communication Channel on sender or receiver side.
    Thanks
    Swarup

  • Command line args from java to C++

    Hi
    I want to pass command line arguemnts argc and argv from java to C++. I have browsed the net and most of them suggested that I declare the jni statement with jObjectarray.
    I saw an example at http://www.csc.calpoly.edu/~fouzi/crossroads/Arguments.c
    It said
    #include "/home/java/linux/jdk118/include/jni.h"
    #include "Arguments.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL
    Java_Arguments_setArgs (JNIEnv *jenv, jobject job, jobjectArray oarr)
    /* obtain the size the the array with a call to the JNI function
    GetArrayLength()                              */
    jsize argc = (*jenv)->GetArrayLength(jenv, oarr);
    /* Declare a char array for argv */
    char const* argv[128];
    int i;
    for (i = 1; i < argc + 1; i++) {
    /* obtain the current object from the object array */
    jobject myObject = (*jenv)->GetObjectArrayElement(jenv, oarr, i-1);
    /* Convert the object just obtained into a String */
    const char str = (jenv)->GetStringUTFChars(jenv,myObject,0);
    /* Build the argv array */
    argv[i] = str;
    /* print the argv array to the screen */
    printf ("argv[%i] = %s\n",i,argv);
    /* Free up memory to prevent memory leaks */
    (*jenv)->ReleaseStringUTFChars(jenv, myObject, str);
    // Increment argc to ajust the difference between Java and C arguments
    argc++;
    // Call a pipeline simulator function which uses command line arguments
    start(argc,argv);
    return;
    That is what I have where the start method is declared like this:
    void start(int argc, /* Argument count */ char argv[] / Argument strings */) {
    But I get a warning when I build the C routine. The warning arises when I am calling the start method.
    The warning says:
    f:\jni\dsaccess.c(711) : warning C4090: 'function' : different 'const' qualifiers
    f:\jni\dsaccess.c(711) : warning C4024: 'start' : different types for formal and actual parameter 2
    Can you help?
    Thanks
    Lakshmi

    1. Your array building looks bogus: Are you missing an index?
    2. You claim to be calling a "method". Are you? Or is it a subroutine?

  • About Command line args

    there is command line argument fir integer like Integer.parseInt(args[0]); can we write same for "char" and" double" also like "Double.parseDouble" or else......

    this has nothing to do with command line arguments
    but yes, all the primitive wrapper classes can parse back their primitive
    Learn to use the API, it's your friend
    http://java.sun.com/javase/6/docs/api/

  • Sun Studio 12 - Can't specify command line args while profiling

    New to Sun Studio development environment, and having trouble profiling my application. I have specified command-line arguments for both Debug and Release builds in Project/Configuration Properties/Runninjg/Arguments and this works fine when running the project from within the IDE. However when I attempt to profile the application through IDE Advanced/Advanced Profiling/Start, my application is launched with no command line arguments. So far I have been unable to find any place to define command line arguments for the program when run using the profiler. Any insights would be greatly appreciated.
    Regards,
    Chad.

    Yes, there is a bug. I reproduced the problem using a sample project Welcome. If I run it without profiling, the program prints correct arguments:
    Welcome ...
    Arguments:
    1: arg 1
    2: arg 2
    [Press Enter to close window] If I run it with profiling "Advanced->Advanced Profiling->Start", the program prints wrong arguments:
    Running "/export/home/SunStudio/SUNWspro/prod/bin/collect  -d /export/home/nikm/SunStudioProjects/Welcome/nbproject/private/experiments -o test.1.er -A on   -p on  -S on  /export/home/nikm/SunStudioProjects/Welcome/dist/Debug/welcome arg 1 arg 2" in /export/home/nikm/SunStudioProjects/Welcome
    Creating experiment database /export/home/nikm/SunStudioProjects/Welcome/nbproject/private/experiments/test.1.er ...
    Welcome ...
    Arguments:
    1: arg
    2: 1
    3: arg
    4: 2
    5: null
    Run successful. Exit value 0.Note, it got 5 arguments instead of 2.
    So, there are two bugs:
    1. argument with spaces is transformed to several arguments.
    2. a "null" argument is added to the list.
    I'll file this bug and let you know the number.
    A workaround is to ignore the last argument in your
    program if it is "null", but this is a very ugly workaround :-)
    Thanks,
    Nik

  • Passing command line args

    I'm a beginner in java and I need to know now to write the code that takes in a randon number of numbers at the command line and stores them in an array
    ie. the program is called number and when I run it, it has to take in the numbers at the command line
    ie. java numbers 12 13 14 15 19 1
    then these numbers are to be stored in an array
    How can I do this??
    Thanking you
    Tom

    public class Numbers {
        public static void main(String[] args) {
            // Convert to integers
            int[] param = new int[args.length];
            for ( int cnt = 0; cnt < args.length; cnt++ ) {
                try {
                    param[cnt] = Integer.parseInt(args[cnt]);
                } catch (NumberFormatException nfe) {
                    System.err.println("Argument " + cnt + " is not integer, using '-1'");
                    param[cnt] = -1;
            // use integers ...
    }

  • Reading directory path as command line args

    Hello,
    I'm trying to write a simple java web server that serves files from a specified directory over a specified port no. (both specified at the command line).
    I am just wondering if any one has any advice on how to handle the directory argument and how check that it is valid etc.
    Thanks
    Gary

    Take a look at the File class, and the method isDirectory, and exists.
    Kaj

Maybe you are looking for