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.

Similar Messages

  • 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

  • Command line options in Jar files?

    Can I set a command line option in the manifest of my jar file so that when it is double clicked it will invoke the JVM with my command line option??

    Trying to pass to the JVM, not my code.I see.
    Actually I wish sun would just fix the dang option towork
    as it should and not need to be on the commandline...
    And that won't happen.
    Your presumption is that the manifest could somehow do
    the command line options. But by the time the
    manifest and jar file is read, the JVM is already
    running and fully functional. Most of the
    functionality that you see in the jvm is actually
    implemented by other java classes. So the JVM has to
    be running before it can do anything.
    With sun jdk 1.3 a hello world program loads 180+
    classes. This is not pre-loading but rather load on
    demand, it needs all of those classes to load, resolve
    and run the hello world program.
    Actually I am aware of the classes which implement this functionality. It would be VERY easy for sun to empty the connection cache, they just choose to not let us do it for whatever bonehead reason. ANYONE who uses an internet inabled java application/applet will have this issue. Is java supposedly internet friendly?
    Just try it. unplug your internet, use a java application to try and connect to some URL (telnet, ftp, whatever). Plugin your internet connection and see that you will not be able to connect untill you restart your app.
    Crazy. This should be implemented. Its got 2 be a bug. they dont even tell you its command line only...

  • Sending Command Line Arguments to Jar Executable

    Hi All
    I wish to send Command Line Arguments to Jar Executable.
    i.e. before I Jar'd my program, I would do the following
    public class CmdLnArgmntExp {
    public static void main(String[] args) {
    System.out.println("d");
    for (int i = 0; i < args.length; i++)
    System.out.println(args);
    Running the program in Console.
    Java CmdLnArgmntExp arg1 arg2 arg3 arg4Output:
    arg1
    arg2
    arg3
    arg4
    How would I do this to a Jar executable, hope that made sense
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    java -jar executable-jar-file-containing-class-CmdLnArgmntExp.jar arg1 arg2 arg3 arg4

  • Capturing command line output to a file possible?

    Hi, i am in need of capturing the command line output to a txt file and need some suggestions on how to do it.
    I have two classes, class A is the one with all the methods and outputs text to the command line (using System.out.print). class B is the one that calls the methods and needs to record the command line output to a file.
    Now the problem i face is not all the output is going to be written to a file and not all the output is going to be displayed on the command line. eg. class B will have a way to select the output mode which is either both to a file and command line or just to a file and display nothing on the command line.
    Is what i am asking even possible? Any suggestions would be great!

    Here is a class I found on the forum that does basically what you need. Just change the code that is updating a Document to write to a file:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ConsoleOutputStream extends OutputStream
         private Document document = null;
         private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
         private PrintStream ps = null;
         public ConsoleOutputStream(Document document, PrintStream ps)
              this.document = document;
              this.ps = ps;
         public void write(int b)
              outputStream.write (b);
         public void flush() throws IOException
              super.flush();
              try
                   if (document != null)
                        document.insertString (document.getLength (),
                             new String (outputStream.toByteArray ()), null);
                   if (ps != null)
                        ps.write (outputStream.toByteArray ());
                   outputStream.reset ();
              catch(Exception e) {}
         public static void main(String[] args)
              JTextArea textArea = new JTextArea();
              JScrollPane scrollPane = new JScrollPane( textArea );
              JFrame frame = new JFrame("Redirect Output");
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.getContentPane().add( scrollPane );
              frame.setSize(300, 600);
              frame.setVisible(true);
              System.setOut( new PrintStream(
                   new ConsoleOutputStream (textArea.getDocument (), System.out), true));
              System.setErr( new PrintStream(
                   new ConsoleOutputStream (textArea.getDocument (), null), true));
              Timer timer = new Timer(1000, new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        System.out.println( new java.util.Date().toString() );
                        System.err.println( System.currentTimeMillis() );
              timer.start();
    }

  • What is the command to create a jar file through Command Promt?

    Hi,
    I done my java project. Now i need to create a exe or jar file to fully complete it. I decided to create a jar file. Because, It'll support both PC and MAC. I exported my JAR file through eclipse. But that jar file loads without images and icons when it is in other directory. How can i include images folder in a JAR File.
    For ex:
    I have parent folder named "Support". Under this there is 3 subfolder namely
    bin - Classes
    src - java files
    images - image files.
    I need to create jar file to "Support" folder which should contain all the above mentioned sub folders.
    I need to execute this jar file anywhere which should not depend on the above mentioned folders which mean adding the images folder in that created jar file.
    Pls guide me for this problem.
    Thanks in advance
    Regards,
    Mohan

    But that jar file loads without images and icons when it is in other directory.Images should be accessed via a URL rather than using a filename because they will exist as entries in the jar archive not as files. Typically this URL would be obtained by using the Class method [getResource()|http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResource(java.lang.String)]. There are details in this [Java World article|http://www.javaworld.com/javaworld/javaqa/2002-11/02-qa-1122-resources.html].

  • Setting IIS W3C Extended Log File settings via command line, registry or configuration file

    I am currently in need of a way to set IIS W3C Extended Log File settings via command line, registry or configuration file.  More specifically the 'Bytes Sent (sc-bytes)' and 'Bytes Received (cs-bytes)' settings that are not enabled by default. 
    If anyone knows where I can locate these setting (outside of the GUI) for all IIS versions that would be greatly appreciated.

    I believe I have found a valid solution. You must have the WebAdministration module loaded.  I hope this helps someone.
    Use the following syntax to view current W3C fields:
    Get-WebConfiguration -filter system.applicationhost/sites/sitedefaults/logfile | select-object -expandProperty logExtFileFlags
    Use the following syntax to set W3C fields:
    Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags -Value "Date,Time,ClientIP,UserName,SiteName,ComputerName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,BytesSent,BytesRecv,TimeTaken,ServerPort,UserAgent,Cookie,Referer,ProtocolVersion,Host,HttpSubStatus"}

  • 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.....

  • Netbeans 551: Include all libs in project jar file. Possible?

    Is it possible to manually, or automaticly, include the /dist/lib directory into my "GonioLabt,jar" to make it more 'stand alone', file wise.
    Netbeans generates this dist/README.TXT
    ========================
    BUILD OUTPUT DESCRIPTION
    ========================
    When you build an Java application project that has a main class, the IDE
    automatically copies all of the JAR
    files on the projects classpath to your projects dist/lib folder. The IDE
    also adds each of the JAR files to the Class-Path element in the application
    JAR files manifest file (MANIFEST.MF).
    To run the project from the command line, go to the dist folder and
    type the following:
    java -jar "GonioLab.jar"
    To distribute this project, zip up the dist folder (including the lib folder)
    and distribute the ZIP file.
    Notes:
    * If two JAR files on the project classpath have the same name, only the first
    JAR file is copied to the lib folder.
    * If the classpath contains a folder of classes or resources, none of the
    classpath elements are copied to the dist folder.
    * If a library on the projects classpath also has a Class-Path element
    specified in the manifest,the content of the Class-Path element has to be on
    the projects runtime path.
    * To set a main class in a standard Java project, right-click the project node
    in the Projects window and choose Properties. Then click Run and enter the
    class name in the Main Class field. Alternatively, you can manually type the
    class name in the manifest Main-Class element.

    Yes it is possible. The same question has been
    killing me all day. Here is how I did it.
    (I'm on Mac OS 10.4, but this should work anywhere)
    Netbeans produces the following:
    dist/myJar.jar
    dist/lib/swing-layout-1.0.jar
    I would prefer to have only:
    dist/myJar.jar
    But, as you know, myJar.jar requires the class files
    stored in swing-layout-1.0.jar. I unpacked the jar
    files and examined the manifest files. Here is how to
    unpack and repack the jar files into a single jar
    file:
    First, I renamed myJar.jar to myJar.zip and let OS X
    unarchive the jar for me. I did the same for
    swing-layout-1.0.jar.
    I then dropped the MANIFEST.MF file from
    MyJar/META-INF/ into a new folder on my harddrive
    Then, I dropped the package (its a folder full of
    class files) from MyJar/ into the same new folder on
    my harddrive.
    At this point, the new folder contains:
    /newFolder/MANIFEST.MF
    /newFolder/myPackage/
    Then, I grabbed /dist/lib/swing-layout-1.0/org/ and
    dropped that into the new folder.
    We now have in the new folder:
    /newFolder/MANIFEST.MF
    /newFolder/myPackage/
    /newFolder/org/
    Almost done:
    Open the MANIFEST.MF file with a text editor. Mine
    looked like this:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.5.0_07-87 ("Apple Computer, Inc.")
    Main-Class: ohm.GUI
    Class-Path: lib/swing-layout-1.0.jar
    X-COMMENT: Main-Class will be added automatically by
    build
    I replaced the ENTIRE contents of the file with
    this:
    Manifest-Version: 1.0
    Main-Class: myPackage/Main
    Where 'myPackage' is the folder containing my class
    files, and 'Main' is the class containing the
    'main(String[] args) method.
    Save the file and we're ready to repack the archive.
    Open the command line (in OS X this is the Terminal)
    I assume the syntax is the same in windoze; Navigate
    to the new folder you created.
    In OSX: cd /newFolder
    in windoze: cd \newFolder
    Then use java's jar command:
    jar cmf MANIFEST.MF MyJar.jar *
    What this does:
    jar is the command. cmf are flags: the 'c' is for
    creating a new jar archive, the 'm' is to specify a
    premade manifest file, the 'f' tells jar to write the
    results to a file. MyJar.jar is the name you have
    chosen for the resulting .jar file. the '*' is a
    wildcard character that tells jar to put every file
    in the present working directory into the new .jar
    Thats it! This produced myJar.jar which worked fine
    by itself, as it included all the classes from
    swing-layout-1.0.jar. It would be a trivial matter to
    write a shell script to do all this for you, unless
    of course you use something silly like windows, in
    which case you'll have to write a batch file or use
    python or something. Good luck, I hope this saves
    others time, drop me a e-mail if this was at all
    confusing! [email protected]
    You should be aware that doing this may well violate the licensing terms for third-party libraries
    By the way, what's silly about using Windows? Are you saying you don't develop for Windows because it's "silly"?

  • Command line treating a *.class file

    I don't know if its possible, but can a jar be set up to run like a normal executable at the command line? Like dir, ls, tar, gzip, etc... So that the command line doesn't have to be built with the first java XXXClass
    So:
    %> java XXXClass
    becomes
    %> XXXClass
    Is this possible outside of creating a .sh or .bat file that forwards the correct parameters. More or less a wrapper around the command:
    java XXXClass <params>
    Is this possible to accomplish for a jar? If so how?
    What I'm after is not to double click the jar file, though that would be optional too. What I would like is to open a command prompt and just type the file name and have it run like a normal executable without:
    %>java -jar
    prefix.
    L-

    Yes and no.
    It is possible, on windows at least, to create a .bat file that will call java on your jar, and then to register that as the default handler for .jar files
    HOWEVER
    Jar files contain no information whatsoever about what external classpath is needed (ie other jars/projects) which makes this relatively useless in a large project
    I don't know if its possible, but can a jar be set up
    to run like a normal executable at the command line?
    Like dir, ls, tar, gzip, etc... So that the command
    line doesn't have to be built with the first java
    XXXClass
    So:
    %> java XXXClass
    becomes
    %> XXXClass
    Is this possible outside of creating a .sh or .bat
    file that forwards the correct parameters. More or
    less a wrapper around the command:
    java XXXClass <params>
    Is this possible to accomplish for a jar? If so how?
    What I'm after is not to double click the jar file,
    though that would be optional too. What I would like
    is to open a command prompt and just type the file
    name and have it run like a normal executable
    without:
    %>java -jar
    prefix.
    L-

  • Possible to use command line argument in project file?

    In my CI build process I would like to have a command line argument "customer" that should be used in the project file to include customer related files into the project like this:
    <Content Include="..\customers\%(customer)\*">
      <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
    </Content>
    Is that possible?

    Hi pkursawe,
    Try to use the Copy task, topy the custom files into the project, then add these files into the ItemGroup, check this blog post:
    How To: Recursively Copy Files Using the <Copy> Task
    The wildcard will help you to add related files into the project.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • 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

  • Running mxmlc from command line - unable to open file

    Hello all,
    Just tried to get Flex up and running - but have run into
    probably a simple problem. Here's the scenario:
    1. I've put the flex 2.0 installation folder on my C drive
    such that the path is c:\flex_sdk_2
    2. I've set my system path to reference the the mxmlc with
    c:\flex_sdk_2\bin
    3. I've set up a folder on my desktop for my flex programs,
    creatively called 'flex'
    4. From my command line I use 'xmxlc --strict=true
    --file-specs filename.mxml'
    My output is this:
    Loading configuration file <etc>
    Error: unable to open filename.mxml
    As I said before, probably an easy fix but thought I'd put
    something up to see if anybody knew an answer off the top of their
    head? I'm running Windows XP. Home Edition, V. 2002 if it helps.
    Many thanks!
    Shannan

    Nevermind, figured it out. My files had the .txt appended to
    the end of the file-name.
    *der*

Maybe you are looking for

  • NULL index table key value

    ORA-06502: PL/SQL: numeric or value error: NULL index table key value in Package OE_Order_PVT Procedure Lines Where is the problem? thanks Edited by: huak on Feb 5, 2009 5:08 PM

  • A universe from SAP ECC 6.0 and SAP BW 7.3... Possible?

    Hello, We are looking to create one universe from two SAP data sources; 1) SAP ECC 6.0 with EHP5 and 2) SAP BW 7.3 Can this be done? In UDT there is a SAP BW connection that can satisfy need for cubes but connection to ECC is a challenge. I think it'

  • Talagent wants to use the local items keychain

    Since the last upgrade I have repeated boxes that asks me for a password. I can't get rid of these and don;t know what the password is that I'm being asked for. I'm wasting a lot of time going round in circles. Can anyone help?

  • Editing Image database columns From Apex front End

    Hello, How is it possible to edit an image datatype in Application express. Suppose if i want to edit an existing i mage and replace it with an edited version and save the newly edited verison in the database. Is it possible to edit and image from th

  • View creating Cartesian Product.. why....

    i am joining 5 tables in a view.. dont know exactly why it is creating Cartesian product. Below is the query: PROMPT CREATE OR REPLACE VIEW xxpd_ozf_aff_err_int_v CREATE OR REPLACE VIEW xxpd_ozf_aff_err_int_v ( row_id, source_system, source_process_i