Executing Jar Application using Java Programs

Hello there,
How can I run a java application using java programs.
Desc:
public class someapp {
   public static void main(String[] ext) {
       // How can I execute a jar application from here through java code
}

You could use java.lang.Runtime.exec(). Another way could be loading the main class of the jar file and invoking its main method dynamically.

Similar Messages

  • Making Executable Jar file using java Application

    Following Program creates the jar file at specified location. but, I wonder why this file does not execute on double clicking on it, in spite of that the Manifest file contain correct main class file name
    //MakJar.java
    import java.io.*;
    public class MakJar
    public static void main(String[] args)throws IOException{
    Process p;
    String str="D:\\Himesh\\JFiles";
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter(str+"\\mainClass.txt"));
    out.write("Main-Class: TestFrame\n");
    out.close();
    } catch (IOException e) {
    try
         p=Runtime.getRuntime().exec("cmd /c D:\\Java6\\jdk1.6.0\\bin\\javac.exe "+str+"\\TestFrame.java");
         p=Runtime.getRuntime().exec("cmd /c D:\\Java6\\jdk1.6.0\\bin\\jar cvmf "+str+"\\mainClass.txt "+str+"\\Demo.jar "+str+"\\*.class");
    catch(IOException e)
    System.err.println("Error on exec() method");
    e.printStackTrace();
    }

    Sir,
    On execute the jar using a "java -jar. . ." command. it gives the error--
    "Exception in thread "main" java.lang.NoClassDefFoundError : TestFrame"
    On Extracting the files from jar file made by the java program,i found that the manifist file ( containing the name of main class) and t the class file are included in the jar file.
    But if I make the jar file manually it works perfectly.I have even reinstalled the java but the problem persists
    Same thing happen if i use MS-DOS batch file.
    ??????If i put the batch file in the same directory and execute it The resulting jar file works,But
    ??????if the batch file is executed from outside the directory The resulting jar file fails execute.
    what should i do???

  • Executing Jar application using API

    Hi,
    Java tutorial [http://java.sun.com/docs/books/tutorial/deployment/jar/apiindex.html] explains how to launch an application bundled in a jar using API.
    How can you set the class path of the launched application ?
    I tried to have the launched application read a text file that is bundled in the same jar but couldn't.
    Thank you

    Here is a complete example of my problem
    c.java launches App.java
    import java.io.*;
    import java.util.jar.*;
    import java.net.*;
    import java.lang.reflect.*;
    class c
    public static void main(String[] args)
    URLClassLoader ucl;
    URL            url;
    Class<?>       cls;
    Method         m;
    try {
          url = new URL ( "jar","","file:/Exec/App.jar!/" );
          ucl = new URLClassLoader ( new URL[]{url} );
          cls = ucl.loadClass ( "Exec.App" );
          m   = cls.getMethod ( "main",new Class[]{args.getClass()} );
          m.setAccessible(true);
          m.invoke ( null,new Object[]{args} );
    catch ( Throwable t )
            System.out.println("Error launching application\n"+t);
    package Exec;
    import java.io.InputStream;
    public class App
    public static void main ( String[] args )
    new App().launch();
    public void launch()
    InputStream is;
    byte        b[] = new byte[512];
    int         i;
    is = this.getClass().getResourceAsStream ( "Seal.txt" );
    try {
          i=is.read(b,0,b.length);
          System.out.print(new String(b,0,i));
    catch ( Throwable t ) {System.out.println(t);}
    try { is.close(); } catch (Throwable t) {}
    App.jar
    META-INF/
    META-INF/MANIFEST.MF
    Exec/App.class
    Seal.txtNotes:
    1. Running c.class produces java.lang.NullPointerException
    2. If I use is = ClassLoader.getSystemResourceAsStream ( "Seal.txt" ); instead of is = this.getClass().getResourceAsStream ( "Seal.txt" ); and put the jar on the -cp of the command line, it works
    Can you please tell me why I am getting the exception ?
    Thank you

  • Download and execute jars without using javaws

    Hi
    I need to download and execute jars from remote computer. I hava jnlp file, but I strongly need to execute jars without using java web start.
    What is the best way to do this task?
    Thanks in advance :)
    Edited by: joekidd on Aug 3, 2009 5:55 AM

    joekidd wrote:
    The easiest the best:)The easiest way is to hire the programmers who made the Jar, to consult on your behalf to install the program, or advise on its installation. BTW - you said earlier.. "strongly need to execute jars without using java web start." Why? What advantage does that provide?
    So I download needed jars, add them to classpath and run my application (I get all information from jnlp file and pass them to vm and my application).
    But following exception occurs "Exception in thread "main" java.lang.NoClassDefFoundError: javax/jnlp/ServiceManager". What should I do?Get in contact with those programmers, because this app. is dependant(1) on functionality that is only available to web start apps.
    (1) Unless they put that call in there, just to ensure no one can run the app. outside web start. ;-)

  • Is it possible to execute SAPGUI scripts from java program?

    Hi everyone..
         I need to develop an java applications that executes the SAPGUI script or any technique that execute set of transaction as client.
         Is it possible to execute SAPGUI scripts from java program? if so, how it can be achieved? is there any other technique to achieve above mention scenario?.
         it will be more helpful, if docs related to that are shared..
         Thanks in advance

    Oh, bummer. Would be much more convenient if I could just use iTunes for everything. Can't stand WMP. I wonder if WinAmp might be a good compromise?
    Thanks for this answer . . .
    Sharon

  • Is it possible to execute an application using threads in oracle db 11g?

    Hi all, I would like to know if it is possible to execute an application using threads in oracle database 11g. Actualy, I would like to know if is is possible to execute a pl/sql program in a similar way as I run threads in a java application.
    Thanks in advance.
    Edited by: user4073561 on 24/11/2010 05:19

    In oracle there is parallel execution/servers,and this is analogy java threads.Refer
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/manproc006.htm

  • How to make destop application using java

    how to make destop application using java
    i mean to say when we double click on the exe file the program should lounch the application
    for windows

    when i double click ii got the msg
    Failed to lad main class manifest attribute from
    x/x/xyz.jar
    what exatly it meansIt means that your Manifest.MF for the JAR file should contain an attribute called Main-Class pointing to a class containing the main() method.
    Something like this should be present in META-INF/Manifest.MF :
    Main-Class: MyApplicationMain

  • Setting persitent system environment variables using java program

    hai,
    Iam tryng to write installation for an application,which require to set some persistent system environment variables using java program. I have tried using set command Runtime.getRuntime().exec("cmd /c set blah blah "),but this applies only to that particular DOS promt only,i presume.And this is not perisistent.please do help.
    Biju

    The solution I proposed worked only on Windows XP/2003.
    The following solution will work on Windows NT/2000/XP/2003 with JDK 1.2+.
    1- Download the [url http://www.gjt.org/download/time/java/jnireg/registry-3.1.3.zip]JNIRegistry zipped archive.
    2- Open the registry-3.1.3.zip file and extract in the folder of your choice ( Eg. c:\setenv ) only the 2 first files (when sorted by path): ICE_JNIRegistry.dll and registry.jar.
    You don't need to keep the folder tree in the extraction.
    3- Create the following SetEnv.java file in the same folder ( Eg. c:\setenv ).
    import com.ice.jni.registry.Registry;
    import com.ice.jni.registry.RegistryKey;
    import com.ice.jni.registry.RegStringValue;
    import com.ice.jni.registry.RegistryValue;
    public class SetEnv
        static final String REG_HKLM_SUBKEY_NAME = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
        public static void main(String[] args)
        throws Exception
            new SetEnv().exec(args);
        void exec(String[] args)
        throws Exception
            if (args.length != 2)
                throw new IllegalArgumentException("\n\nUsage: java SetEnv {varName} {varValue}\n\n");
            String varName = args[0];
            String varValue = args[1];
            RegistryKey key = null;
            RegStringValue value;
            try
                key = Registry.HKEY_LOCAL_MACHINE.openSubKey(REG_HKLM_SUBKEY_NAME, RegistryKey.ACCESS_ALL);
                value = new RegStringValue(key, varName, RegistryValue.REG_EXPAND_SZ);           
                value.setData(varValue);
                key.setValue(value);
                key.flushKey();
            finally
                try { key.closeKey(); }
                catch (Exception e) {}
    }4- Compile it.
    javac -classpath .;registry.jar SetEnv.java
    5- Run it. varName and varValue are strings of your choice.
    java -classpath .;registry.jar -Djava.library.path=. SetEnv varName varValue

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • How to read system eventlog using java program in windows?

    How to read system eventlog using java program in windows?
    is there any java class available to do this ? or any one having sample code for this?
    Your friend Zoe

    Hi,
    There is no java class for reading event log in windows, so we can do one thing we can use windows system 32 VBS script to read the system log .
    The output of this command can be read using java program....
    we can use java exec for executing this system32 vbs script.
    use the below program and pass the command "eventquery"
    plz refer cscript,wscript
    import java.io.*;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
    String line;
    Process p = Runtime.getRuntime().exec("Command");
    BufferedReader input =
    new BufferedReader
    (new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
    System.out.println(line);
    input.close();
    catch (Exception err) {
    err.printStackTrace();
    This sample program will list all the system log information....
    Zoe

  • Could I run a jar application use a external class such as db2java.zip (ib

    Could I run a jar application use a external resource in a zip format such as db2java.zip (ibmdb2 driver) not a jar format ?

    Yes you can. Make a manifest for your jar, and include the manifest attribute 'Class-Path' that specifies your jar or zip file, like this:
    Class-Path: db2java.zip
    And then have the zip file in the same directory as your jar file. See the Java Tutorial, Jar Trail for more info on manifest, and/or see other messages in this forum.
    -Ron

  • Writing into a jar file through Java program

    Is there a way to get a file from a jar (for ex. a properties file) make changes to it on the fly and write the same file back to the jar through a Java program?

    I cannnot give u exact code as i am bit busy..but i am giving close to exact
    below is code for reading contents of jar file
    import java.io.*;
    import java.util.jar.*;
    public class JarRead {
    public static void main (String args[])
    throws IOException {
    if (args.length != 2) {
    System.out.println(
    "Please provide a JAR filename and file to read");
    System.exit(-1);
    JarFile jarFile = new JarFile(args[0]);
    JarEntry entry = jarFile.getJarEntry(args[1]);
    InputStream input = jarFile.getInputStream(entry);
    process(input);
    jarFile.close();
    private static void process(InputStream input)
    throws IOException {
    InputStreamReader isr =
    new InputStreamReader(input);
    BufferedReader reader = new BufferedReader(isr);
    String line;
    while ((line = reader.readLine()) != null) {
    System.out.println(line);
    reader.close();
    now here say u have test.jar which contains test.txt (file)
    then
    java JarRead test.jar test.txt
    will print content of text.txt
    now in ur case u write content of each file in some other file modify it there and then create a jar file from those files using jaroutput stream .....
    this may not be all clear ..but what to do..bit busy...u are welcomed to make changes in above stratergy....n queries if any after using above stratergy and/or your great brain...

  • Deploying no java applications using Java Web Start

    Hi,
    I am new to java web start. Is it possible to distribute non java applications using java web start. I have an APP which can run on a desktop in standalone mode. The app has jusy HTML and Java script files. Is it possible to package this app and deploying using java web start? I am assuming If it is possible, I can make updates to the packaged app in the web servers and the updates will be downloaded next time the app is used provided configurations are correct?
    thx

    The app has jusy HTML and Java script files. Is it possible
    to package this app and deploying using java web start? Not really. Resources for JWS need to be zipped,
    while this HTML/JS app. will (I guess) not work from
    inside the depths of a Jar (or Zip) archive.
    Note that you can organise for those files to be
    downloaded and expanded onto a known place
    on the user's disk, by using an 'installer' element,
    but..
    ...I am assuming If it is possible, I can make updates to the
    packaged app in the web servers and the updates ..installers are only called once, and do not 'update'.

  • How to get free disk space in linux   Using JAVA program ?

    Hi,
    I am new to such adavance topics.. like JNI
    I have to check linux system free disk space , if space is more than 80% it should email to user.
    But how to check that Using Java program ??
    can u give me one sample example ? i will do it if u can do some for me
    thanks
    give me possible solutions...

    Using the Runtime class you can execute any linux command. Check it out.

  • GIS applications using Java/SDO/MapViewer

    Hi everybody !
    First of all, sorry if my english is not soo good.
    I had installed MapViewer in my computer. It4s working perfectly.
    After view the JSP demo page and the Java demo program, I4m trying to create my own program, using the MapViewer.
    Well, before start my job, I wonder if there is anyone who has already create a application using Java, MapViewer and SDO.
    Is it really possible ?
    How is the productivity ?
    What are the major problems ?
    What are the alternatives ?
    Thanks,
         Rodrigo

    What XML Parser are you using to get an atributte4s value ?
    The JSP Demo makes a string comparison, but I want to use the XML Parser. How can I do this ?
    Response DTD Example:
    ~~~~~~~~~~~~~~~~~~~~
    <?xml version="1.0" encoding="UTF-8" ?>
    <map_response>
         <map_image>
              <map_content url="http://map.oracle.com/output/map029763.bmp" />
              <box srsName="default">
                   <coordinates>-122.260443,37.531621 -120.345,39.543</coordinates>
              </box>
              <WMTException version="1.0.0" error_code="SUCCESS"/>
         </map_image>
    </map_response>
    Questions:
    ~~~~~~~~~~~~~~
    - How can I get the value of the url atributte (http://map.oracle.com/output/map029763.bmp) ?
    - How can I get the value of the error_code atributte (SUCCESS) ?
    I4m holding the response DTD sending by MapViewer on a String variable.
    Thanks,
    Rodrigo

Maybe you are looking for

  • Are there any other hidden editing options?

    Thanks to this forum, I've found the redeye tool in iPhoto to be quite useful, but this wasn't the case before I found out about the Caps-Ctrl-9 trick that was posted in this forum. Are there any other tricks that anyone has discovered in iPhoto that

  • VMWare Fusion - Cannot see other computers in the Workgroup

    For some reason I'm unable to see or access other machines in my Windows Workgroup from within Fusion 1.1.3. Alternatively, I cannot see or access the VM from other WinXP machines in my workgroup. The other WinXP machines in my workgroup CAN at least

  • My apple TV ID is not recognised in Apples Data Base

    I recently changed my Itunes account ID to a generic Gmail account in case I changed my internet provider in the future, after a few days I changed my apple TV ID to match it. Now it says  "does not recognise this ID in its Data base". I have checked

  • Songs getting cut off

    okaay so my problem is whenever I import a cd into all seems okay until I sync the songs into my ipod. It seems that the first song is always cut off and then it skips to the next song. Does anybody else seem to have this problem? How do I solve this

  • Browser file won't open

    I'm trying to open a file of media clips & sequences to the browser. They're in Documents>Capture Scratch>P2 folder. When I click on P2 folder it opens the list in the right column. But it won't open the whole list in the brower where I need them. It