Run applications ( .jar files) by bash on linux

On linux:
I have a swing application and its jar file. I created an executable file using bash script to run the jar file
#!/bin/bash
java -jar myapp.jar
this runs in console normally but when i clicked the executable file, the application runs too but immediately closes. I think the problem is that this can't recognize the swing-layout.jar (swing library) so that the swing components (JFrame,Jbutton) cannot be showed!
There must be a way for the executable file to recognize the libraries (swing, layouts) for the application by using bash script ?

There can be number of reasons for that. I suggest you following way:
1. Modify your script in following way:
#!/bin/bash
java -jar myapp.jar 2>/tmp/log.err 1>/tmp/log.out
After unsuccesful execution check content of /tmp/log.* files and see details of the error.
Often such errors are caused by environment. May be you just don have java in your PATH .. May
be DISPLAY is not set .. I don't know.
To workaround env issue you need to dump environmentin from console:
declare -x >env.sh
After that include update your .sh script in following way and see the difference:
#!/bin/bash
. env.sh
java -jar myapp.jar 2>/tmp/log.err 1>/tmp/log.out

Similar Messages

  • How can i run a jar file as EXE on mouse click..

    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*

    amrit_j2ee wrote:
    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*Do you mean converting it from a jar file to an EXE file or do you mean that you would like to run the application by just double clicking it?
    If it's the latter then you need to make the jar file including a manifest.
    The manifest can be just a txt file with its content to be something like this:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: Somebody
    Main-Class: NameOfTheMainClass
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by buildTo make the jar file including the manifest, use something like this in your command prompt (of course you must have compiled your java file(s) first):
    jar cfm test.jar MANIFEST.txt NameOfTheMainClass.classAfter that you'd be able to run your application just by double clicking it.
    If you're a NetBeans user, you can build your standalone application by right-clicking your project and then going to properties => run => and choosing a Main class. After that right click on that project and "Clean and Build", locate the jar file in the "dist" folder and double click it =]
    Hope it helps,
    LD

  • OutOfMemory Exception while running a JAR file

    Hi,
    I am working with Java 1.5 and using Eclipse to build a GUI. My application has intensive image loading involved so I set -Xmx inside Eclipse when running the application in debug mode.
    However, once a JAR file is exported, I do not know how to specify the heap size required to run the program. Is there a way to ...
    1. embed the heap size info inside the JAR file?
    2. specify a heap size when running the JAR file?
    Thanks in advance.

    Heap size is specified by the -Xmx option on the java command. See the java command documentation.

  • Running a jar file from java code

    Hi!
    Im trying to run a jar file from my code.
    I've tried Classloader, but that doesnt work because it doesnt find the images (also embedded in the 2nd jar file).
    WHat I would like to do is actually RUN the 2nd jar file from the first jar file. There must be a way to do this right?
    any ideas?

    ok, I found some wonderful code (see below) that will try to start the jar. But it doesn't. What it does is produce the following error when my application runs...
    So it's not finding the images in the jar file that I am trying to run? Strange. I checked the URL that sending, but it seems ok....
    I think I will check the url again to make sure......
    any ideas?
    Uncaught error fetching image:
    java.lang.NullPointerException
         at sun.awt.image.URLImageSource.getConnection(Unknown Source)
         at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
         at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
         at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
         at sun.awt.image.ImageFetcher.run(Unknown Source)
    the code....
    /* From http://java.sun.com/docs/books/tutorial/index.html */
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    import java.net.JarURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.jar.Attributes;
    * Runs a jar application from any url. Usage is 'java JarRunner url [args..]'
    * where url is the url of the jar file and args is optional arguments to be
    * passed to the application's main method.
    public class JarRunner {
      public static void main(String[] args) {
        URL url = null;
        try {
          url = new URL(args[0]);//"VideoTagger.jar");
        } catch (MalformedURLException e) {
          System.out.println("Invalid URL: ");
        // Create the class loader for the application jar file
        JarClassLoader cl = new JarClassLoader(url);
        // Get the application's main class name
        String name = null;
        try {
          name = cl.getMainClassName();
        } catch (IOException e) {
          System.err.println("I/O error while loading JAR file:");
          e.printStackTrace();
          System.exit(1);
        if (name == null) {
          fatal("Specified jar file does not contain a 'Main-Class'"
              + " manifest attribute");
        // Get arguments for the application
        String[] newArgs = new String[args.length - 1];
        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
        // Invoke application's main class
        try {
          cl.invokeClass(name, newArgs);
        } catch (ClassNotFoundException e) {
          fatal("Class not found: " + name);
        } catch (NoSuchMethodException e) {
          fatal("Class does not define a 'main' method: " + name);
        } catch (InvocationTargetException e) {
          e.getTargetException().printStackTrace();
          System.exit(1);
      private static void fatal(String s) {
        System.err.println(s);
        System.exit(1);
    * A class loader for loading jar files, both local and remote.
    class JarClassLoader extends URLClassLoader {
      private URL url;
       * Creates a new JarClassLoader for the specified url.
       * @param url
       *            the url of the jar file
      public JarClassLoader(URL url) {
        super(new URL[] { url });
        this.url = url;
       * Returns the name of the jar file main class, or null if no "Main-Class"
       * manifest attributes was defined.
      public String getMainClassName() throws IOException {
        URL u = new URL("jar", "", url + "!/");
        JarURLConnection uc = (JarURLConnection) u.openConnection();
        Attributes attr = uc.getMainAttributes();
        return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
       * Invokes the application in this jar file given the name of the main class
       * and an array of arguments. The class must define a static method "main"
       * which takes an array of String arguemtns and is of return type "void".
       * @param name
       *            the name of the main class
       * @param args
       *            the arguments for the application
       * @exception ClassNotFoundException
       *                if the specified class could not be found
       * @exception NoSuchMethodException
       *                if the specified class does not contain a "main" method
       * @exception InvocationTargetException
       *                if the application raised an exception
      public void invokeClass(String name, String[] args)
          throws ClassNotFoundException, NoSuchMethodException,
          InvocationTargetException {
        Class c = loadClass(name);
        Method m = c.getMethod("main", new Class[] { args.getClass() });
        m.setAccessible(true);
        int mods = m.getModifiers();
        if (m.getReturnType() != void.class || !Modifier.isStatic(mods)
            || !Modifier.isPublic(mods)) {
          throw new NoSuchMethodException("main");
        try {
          m.invoke(null, new Object[] { args });
        } catch (IllegalAccessException e) {
          // This should not happen, as we have disabled access checks
    }

  • Unable to Run a .jar file in pjava

    I have installed pjava (for StrongArm) on to my iPAQ Pocket PC H3660.
    Then I created a simple application using JBuilder and created a *.jar file of the classes. I have used the awt classes to build the interface. I am using JDK version 1.3.0.
    When I deploy it into my Pocket PC and run the jar file, the compiler loads up and I get the error message "Cannot find class : packagename.classname".
    I have checked the jar file contents in JBuilder and the class files are all in there.
    Could anyone help me on this? Thanks!

    If you are compiling with JDK1.3 (or any compiler > java 1.1.8), you have to use the parameter "-target 1.1" to make sure the class files will be loaded by a 1.1 JVM. Jeode doesn't seem to care about this setting, but when we switched to Creme the problem arose.
    -Eric

  • Button action - run separate jar file

    My first post here (hopefully many more to be:D) and I have an interesting question which I haven't thought out how to realize it.
    Imagine you run the NetBeans template for a sample GUI application. You add a button, and the action of the button when pressed to be to run another jar file (and maybe pass parameters to it).
    How can I do that? Or is it even possible? I know that it isn't simple as to import the other project and to set the action to "java -jar theotherapp.jar".

    Thanks for the fast reply and for the good suggestion.
    I think I'll try with ProcessBuilder (I used Java till recently only for data structures and similar, so all of these stuff -gui building, making desktop apps, is new to me :D people only have to be pointed into the right direction).

  • Html script to run a Jar file

    Is it possible to automatically run a .jar file from an .html page? Here is my issue:
    I have a software script for athletes that runs from a jar file. I need to create an index.htm file in order to use the compiler software that I am using.
    So I am trying to figure out if there is a script to put in the index file that will immediately run the main .jar file. I don't want the viewer (athlete) to even see the index file so the only code I will put in there will be to run the .jar file.
    Is this possible?
    thank you!

    This all sounds very confused.
    There are applets (Java applications embedded in a webpages).
    There are stand alone applications (Java applications that are by themselves no web page required)
    There are servlets ( Java applications that produce HTML pages [and other web content])
    This bit about my compiler needs it makes no sense. And I don't know which of the above you have or are trying to be honest. I will tell you this, it is one of them (probably the first two).
    So which one of those are you trying to make? If you say none of them then please think harder because that is not a valid answer.

  • How to run a jar file in a browswer?

    Hi, everyone:
    I got a problem here. I would like to run my jar file in a html-based brower, should I write another applet for my jar file? How can I do that? (I don't have applet in my jar file, but only JFrame) Is there any way I can put a runnable jar file into an applet and show on the brower? Could anyone show me how to write this code? Thank you very much!!
    -jxchou

    At first you need a java plug-in for your browser.
    Next you have to implement an applet in your jar-file.
    The tag in your html-document should look like:
    <applet code="Sample.class" archive="sample.jar" width="400" height="400"></applet>

  • How to run a jar file in JBuilder

    Hi there
    I need to know how to run a jar file using JBuilder. Thanks :)
    Countess

    well i have a german version of jbuilder and there it is under
    experten Archiv-builder
    look at something that has a similar name

  • How to run a JAR file in Unix system?

    hi there
    ca anyone tell me how to run a JAR file in unix system or X window, thank you

    You want to create an executable JAR file? You do it in the following way.
    Create a manifest file such as manif.txt and the contents should contain
    Main-Class: foo
    assuming foo is the name of your main class. Then create the jar as follows
    jar cvfm foo.jar manif.txt foo.class
    I hope that helps you!
    you can find more info here http://java.sun.com/docs/books/tutorial/jar/

  • Run a JAR file!!!

    How to run a JAR file....

    you need to specify the
    Main-class: your class contains main method here
    attrbute in Meta-inf
    nd you can run usinf
    java -jar yourjar.jarThe question was not, "How do I create a manifest file that will allow me to run my jar file?" It was simply, "How do I run a jar file?"

  • Application jar file is corrupt

    Hi Everyone,
    Having written a very simple application using ME software develeopement kit, when ran the emulator prompts me to either INSTALL APPLICATION or MANAGE CERTIFICATE AURTHORITIES.
    If INSTALL APPLICATION is selected I'm then prompted to ENTER A WEBSITE TO INSTALL FROM into a textbox. MANAGE CERTIFICATE AURTHORITIES presents some spurious code and I don't know what it means. However when ran for the first time, everything seemed to go swimmingly untill I was informe of (I Think) 'Application jar file is corrupt' and then subsequently as described above.
    I don't know a great deel about computers, but looks to me like a random problem requiring a random solution - very frustrating! If anyone would like to help I'd be very greatful indeed.
    James

    pavanpotru, welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
    I'm locking this thread now.
    db

  • Is it possible to run a jar file in another program???

    Hello members,
    i am sanketh. is it possible to run a jar file in another program.
    if possible plz reply with an example or good links to go thru.

    What do you mean "run a jar file in another program"? It's not very clear.

  • Getting error when running the jar file..

    Hi All,
    I am new to executing jar file..Actually i have one class which contains the following code.
    import com.documentum.fc.client.DfClient;
    import com.documentum.fc.client.IDfClient;
    import com.documentum.fc.client.IDfSession;
    import com.documentum.fc.client.IDfSessionManager;
    import com.documentum.fc.common.DfLoginInfo;
    import com.documentum.fc.common.IDfLoginInfo;
    import com.documentum.fc.common.DfException;
    import com.fidelity.ftg.ereviewg2.migration.util.MigrationResource;
    * This class is used for creating docbase connection
    * *@type* DocbaseConnection
    * *@author* a405304
    * *@see*
    public *class *DocbaseConnection {
    //public static ResourceBundle resource;
    IDfSessionManager sMgr = *null*;
    IDfSession session = *null*;
    String docbaseName;
    *private* *static* DocbaseConnection +docbaseCon+;
    * Constructor for DocbaseConnection
    * *@throws* DfException
    * *@throws* Exception
    *private* DocbaseConnection()*throws* DfException, Exception{
    //ResourceBundle bundle = ResourceBundle.getBundle(Constants.RESOURCE_PATH,Locale.getDefault());
    MigrationResource bundle = MigrationResource.+getBundle+();
    String userId = bundle.getString("DOCBASE_USERID");
    String password = bundle.getString("DOCBASE_PASSWORD");
    docbaseName = bundle.getString("DOCBASE_NAME");
    IDfClient client = DfClient.+getLocalClient+();
    sMgr = client.newSessionManager();
    IDfLoginInfo loginInfo = *new* DfLoginInfo();
    loginInfo.setUser( userId );
    loginInfo.setPassword( password );
    loginInfo.setDomain("");
    sMgr.setIdentity( docbaseName, loginInfo );
    session= sMgr.getSession( docbaseName );
    System.+out+.println("# Connected to Docbase: "+session);
    }Now i create the jar file whose name is docbaseconnection.jar
    Now when i am running this jar file by using the following command then i am getting the following error..
    C:\JAR_FILES>java -jar docbaseconnection.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: com/documentum/fc/client/DfQuery
    For running this docbaseconnection.jar file i need the following thing in classpath...
    C:\Program Files\Documentum\dctm.jar;C:\Program Files\Documentum\Shared\dfc.jar;C:\Program Files\Documentum\Shared\log4j.jar
    I already add this jar files in the classpath of environment variables..Then also i am getting the same error..
    Kindly help me...........

    Well, let´s supose your manifest is defined as I did in my previous post. So, your directory base should be something like:
    C:\dir
    docbaseconnection.jar
    dctm.jar
    dfc.jar
    anotherlibraries.jar
    But, let´s supose you want something like
    C:\dir
    docbaseconnection.jar
    lib (folder, which contains dctm.jar, dfc.jar, etc)
    Then you should change the class-path of your manifest to
    Class-Path: ./lib/dctm.jar ./lib/dfc.jar
    That´s what I meant

  • Help with running java .jar file

    Hi I just installed java with
    # pacman -S jre
    and when i try to run
    java -jar file.jar
    it says command not found. so what do i need to install to be able to run java .jar files through the CLI?

    do, what vintendo says. because it cant find the java in the default paths.

Maybe you are looking for

  • Oracle 8.1.7 + RedHat 7.3 installation success

    After several days of work, I succeded in installing Oracle 8i on RedHat 7.3. 1)You can proceed like usual for the account + groups creation. 2)Make the oracle directory. 3)This is what i add in my /home/oracle/.bash_profile PATH=$PATH:$HOME/bin expo

  • "Create Action" button not show in the control issue screen

    Hi All, When I access update issue screen and want to assign person I cannot found "Create Action" button to do this, Why? and how do I show this button? Thank you.

  • Low bandwidth with E3000 router

    Hello. I just purchased an E3000 router to replace my old d-link. We have Telia ADSL (8 Mbit) and I've had little or no problems using a router before. When my computer connects directly to the modem I get 7 Mbit out of the connection but with the E3

  • Working with NWDS...and property files

    Hi all.  I am trying to execute some of the examples in the Development & Extension Guide Tutorial and I have a question.  I am using NWDS and have built a new B2B application and deployed it, I am trying to add a new field and have made some modific

  • Client Configuration Tool

    What is the real purpose of this software client applicaiton? Do you run it from each desktop before installing CAD or Supervisor? If you are upgrading from one verison to the next, do you need to run it again?