Running exe contained in jar file

Hello,
I have written a java interface where an external executable is being called from one of the classes. I'm using Jgrasp as development environment.
Everything works fine if I run the java program from within Jgrasp: the interface opens up fine and it can run the external program when the button which is supposed to start it is clicked on.
I have then generated a JAR file containing all the classes etc and also the external executable.
When I execute the Jar file, the interface opens up ok and everything works fine within it, but it cannot run the external executable any more.
Is it possible to run an exe file contained in the jar file itself?
I would like to distribute a single jar file containing all the files needed by the application.
Thanks

An EXE can only be executed from Java if it resides somewhere in the file system.
This is obviously the case before you JAR the whole thing, but not after.
Your code will need to extract the EXE by using Class.getResourceAsStream() and
copy it to a temporary location in the file system before executing it.

Similar Messages

  • Images not getting Loaded while running Java Application through jar file

    Hello Friends,
    I have a problem while starting my application.I have written my application using pure java.There is no JSP or anything just pure swings.Mine is a standalone appplication.So i used to run it using a batch file.And when i used to start my application it used to not show me the images.so what i did was i mentioned the starting directory in the properties of the batch file (ie in the start in column field).But that was when i was using weblogic server.And i have lot of people working on the same application.so i used ZAC publisher in weblogic and along with that i used to publish the batch file also.so the users dint have any problem.But now what is my problem is i m trying to use JAVA Webstart instead of weblogic ZAC.Now in webstart what happens is that i have to run the appliaction thru jar file.so where do i mention the class path so that the images get loaded.As of now the imaes are not getting loaded.i feel this is a class path problem.but where do i mention it that is my problem.It would be really helpfule if someone could help me out.
    thanx and regards,
    [email protected]

    try out this
    ImageIcon img1=new ImageIcon(this.getClass().getResource(imagename));
    for exmaple
    Imageicon img1=new ImageIcon(this.getClass().getResource("name1.jpg"));
    dont 4get to include the image files in the jar file

  • Applet won't run if put in JAR file

    Hello, I've searched a lot and couldn't find an answer to my problem -
    I want to put my applet into a jar file. and run it, of course.
    I have a jar file that contains "b.class", "temp.class" both of them in directory "package_name", which is their package's name in eclipse. (this jar I obtained by using export from eclipse).
    and - I have my index.html file -
    <APPLET
    CODE="b.class"
    ARCHIVE "jar_file.jar"
    WIDTH="100%" HEIGHT="90"
    </APPLET>
    both the index.html and the jar file in the same directory.
    and the applet wont run!
    what am I doing wrong? somehow I think that the problem is because the classes reside in another directory in the jar file,
    but I already tried everything - with no success :(
    Kogan.

    OK the problem solved -here is highlighted what I was missing -
    <APPLET
    CODE=package_name.b.class ( I was missing the "package_name")
    codebase = "."
    ARCHIVE "jar_file.jar"
    WIDTH="100%" HEIGHT="90"
    </APPLET>
    Edited by: Kogan on Nov 3, 2008 6:51 AM
    Edited by: Kogan on Nov 3, 2008 6:52 AM

  • Executing an file.exe from a jar file?

    Does anyone know how to execute an *.exe file from jar file?
    I have two files that I want to execute in one java.class, Monview.exe and Moninit.exe. Both are stored in the same jar file as the class called link.class.
    This is my code to run one of the files from the hard drive
    String []cmd={"c:\\monview.exe"};
    try
    Process pr = Runtime.getRuntime().exec(cmd);
    StringBuffer buf = new StringBuffer();
    InputStream istr = pr.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(istr));
    String str;
    while ((str = br.readLine()) != null) {      
                             buf.append(str);
    try {       
    pr.waitFor();
    } catch (InterruptedException e) { }
         if (pr.exitValue() != 0) {      
         br.close();
    catch (IOException e){}
    It works when i place both .exe on the local host harddrive but when I place it in the jar file nothing happens. Could anyone help me please on why does this happen and how I can fix it? Or on how to get the link.class code to extract it from the jar file and place it on the system directory and delete it from the system directory, without it knowing where the jar file comes from?

    Hello,
    If I am not mistaken, by including the JAR file in the CLASSPATH (specifying the absolute path), or after the -classpath option after the java command (java -classpath jar_archive main_class), the system will find both files in the JAR archive.
    Hope this helps!

  • How to run Java App in Jar file

    I can run Java App jar-ed into 1 jar file with java -jar App.jar
    But sometimes I need to jar only the app and bind the other classes from different place. So I tried to use:
    java -classpath c:\utils.jar -jar App2.jar
    where classes in App2.jar link to utils.jar. I just can't make it work. Any idea/help.
    thanks
    -ho

    hi HasanOen
    u need to edit the manifest file in yr JAR file u can do this by using the following cammand or by making the batch file but make sure all the files are in same folder.
    first of all u need to make a text file like below
    /////////// first file name: "THIS.txt" /////////
    Manifest-Version: 1.0
    Created-By: java // whatever here
    Main-Class: PUT YOUR MAIN CLASS NAME HERE (like MAIN)
    //////////////////// BATCH FILE "RUN.bat" //////////////
    jar cmf This.txt App2.jar MANIFEST.mf com
    com is the folder where your all the class file are.
    now double click the run.bat file. this will edit yr manifest file.
    hope this should work for u
    Note : Make sure yr jar file, txt file, bat file, and yr classes folder is in the same folder(I mean at same level)
    regards
    Satinderjit

  • Exe-jar file

    Good day, could someone please help with a little problem I have encountered,
    I have built and a swing application that connects to MySQL database using Netbeans IDE, The problem I am experiencing goes like this. I have a login in window of which if a username and password match the username and password on the database then my login in frame is disposed off, then the main application frame appears, the strange thing is when I compile and run it from the IDE (Netbeans) it works fine, but as soon as I try run it from a jar file or make and exe using exej the main application frame does not appear after the login is successful.
    Can someone please cast a light on this matter?
    Thank you.

    This is the error i get from exej
    java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
         at java.lang.Class.getDeclaredMethods0(Native Method)
         at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
         at java.lang.Class.getDeclaredMethod(Unknown Source)
         at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
         at com.exe4j.runtime.WinLauncher.main(Unknown Source)

  • How to run tools from a java archive (jar file)

    I used to run Multivalent from http://multivalent.sourceforge.net/ but am now getting error messages like this:
    Exception in thread "main" java.lang.NoClassDefFoundError: tools/pdf/Impose
    This happens even when I'm in the directory containing the jar file.
    I've never installed it by myself though so am not sure that I've done it right. I put the jar file into ~/library/java but that was a guess after reading lots of web pages that don't quite say what to do. They assume that I've read some intro material that I haven't been able to find.
    Any pointers on where I can find out how to do this right?
    In case it's relevant, java -version returns:
    java version "1.5.0_16"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
    Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)
    and echo $CLASSPATH returns a blank line.

    Not necessarily. The -cp parameter can include a complete file spec. You can create a Unix alias for the whole command line. For example:
    alias compress='java -cp ~/JarFolder/Multivalent20060102.jar tool.pdf.Compress'
    I use Multivalent tools a lot for maybe a week at a time, then don't touch them for a couple of months. During the downtime I'd just forget aliases like this.
    On Macs, the default classpath includes the folder /Library/Java/Extensions. If you drop the jar file into this folder then you won't need to specify an explicit CLASSPATH variable nor the -cp option.
    I thought so too, but it doesn't appear to be the case on my computer. Both /Library/java/extensions and ~/library/java are on DefaultClasspath but CLASSPATH is empty. And even when the directories are specified, the jar file in it is ignored unless I specify that explicitly as well. I do not remember needing to do that in the past. It used to just work when it was in a classpath directory.
    I get the impression that something has changed in how Mac Java handles the classpath. In searching for answers I noticed that many people were attributing their difficulties to a classpath change in a recent update. It is not something that I see myself dealing with in the near future. But it would be helpful to know of a primer for newcomers to Java and the OS X directory conventions so they know where to put things and what paths to set for basics like this.

  • Access JAR File while running App with Java Web Start

    Hello guys,
    I want to delpoy my application so that I can run it when I click on the appropriate button in a web page.
    I have a Jar file for all the files that the app needs. No, not all of the files are included.
    Indeed, I use JAR files such jdom.jar or postgres...jar that I must use in within my application.
    How can I access these JAR files knowing that I can't point to files in a JAR file A from within a JAR file B, if the JAR file B contains the JAR file A?
    The main JAR file that I put on the web server can be seen as the JAR file B and the other JAR files must be stored somewhere for the java classes within the main JAR file to have access to them.
    I wonder whether there is another way to structure the project.
    Thanks.

    Hi Andrew.
    I have followed your suggestions and here is what my .jnlp file look like:
    <tt>
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/koedops" href="beta.jnlp">
         <information>
              <title>KOEDOPS</title>
              <vendor>Pr. Fischer</vendor>
              <homepage href="http://localhost:8080/" />
              <description>Downloading koedops with Java Web Start</description>
         </information>
         <resources>
              <j2se version="1.6+" />
              <jar href="beta.jar" main="true"/>
              <jar href="jcalendar-1.3.3.jar" />
              <jar href="jdom.jar" />
              <jar href="postgresql-8.4-701.jdbc4.jar" />
         </resources>
         <application-desc main-class="general.Application" />
    </jnlp>               
    </tt>
    The three other jar-files reside in the same directory as the .jnlp file and the beta.jar file on the tomcat server.
    When I launch the application though nothing happens upon the download. In contrast, if I change the main class to a class file that requires no extra library, it runs perfectly.
    I can't be sure whether the jar-files are successfully accessed.
    Regards.
    Edmond

  • Determining the name of the jar file running from JAVA

    Hi everyone,
    This is probably a silly question, but how do you determine the name of the jar file running from within the jar file.
    E.g. If I'm running the jar file "Test.jar", then how can I get the String value "Test.jar" from within my program?
    Any help would be appreciated! Thanks:)

    I think that you can use the solution above to get the jar file resources associated with a particular jar file, and then use the JarFile class to get a manifest of whats in there, and then find your class?
    This is only off of the top of my head, and I haven't tested it. Let me know if it works

  • How to create and use library JAR files with command-line tools?

    Development Tools -> General Questions:
    I am trying to figure out how to put utility classes into JAR files and then compile and run applications against those JAR files using the command-line javac, jar, and java tools. I am using jdk1.7.0_17 on Debian GNU/Linux 6.0.7.
    I have posted a simple example with one utility class, one console application class, and a Makefile:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130520-2134.tar.gz
    Here is a console session:
    2013-05-20 21:39:01 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-20 21:39:12 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/hello/HelloConsole.java
    package com.example.hello;
    import static com.example.util.Hello.hello;
    public class HelloConsole {
        public static void main(String [] args) {
         hello("world!");
    2013-05-20 21:39:21 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -f hello
    find . -name '*.class' -delete
    javac src/com/example/util/Hello.java
    javac -cp src src/com/example/hello/HelloConsole.java
    echo "java -cp src com.example.hello.HelloConsole" > hello
    chmod +x hello
    2013-05-20 21:39:28 dpchrist@desktop ~/sandbox/java/jar
    $ ./hello
    hello, world!I believe I am looking for:
    1. Command-line invocation of "jar" to put the utility class bytecode file (Hello.class) into a JAR?
    2. Command-line invocation of "javac" to compile the application (HelloConsole.java) against the JAR file?
    3. Command-line invocation of "java" to run the application (HelloConsole.class) against the JAR file?
    I already know how t compile the utility class file.
    Any suggestions?
    TIA,
    David

    I finally figured it out:
    1. All name spaces must match -- identifiers, packages, file system, JAR contents, etc..
    2. Tools must be invoked from specific working directories with specific option arguments, all according to the project name space.
    My key discovery was that if the code says
    import com.example.util.Hello;then the JAR must contain
    com/example/util/Hello.classand I must invoke the compiler and interpreter with an -classpath argument that is the full path to the JAR file
    -classpath ext/com/example/util.jarThe code is here:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130525-1301.tar.gz
    Here is a console session that demonstrates building and running the code two ways:
    1. Compiling the utility class into bytecode, compiling the application class against the utility bytecode, and running the application bytecode against the utility bytecode.
    2. Putting the (previously compiled) utility bytecode into a JAR and running the application bytecode against the JAR. (Note that recompiling the application against the JAR was unnecessary.)
    (If you don't know Make, understand that the working directory is reset to the initial working directory prior to each and every command issued by Make):
    2013-05-25 14:02:47 dpchrist@desktop ~/sandbox/java/jar
    $ cat apps/com/example/hello/Console.java
    package com.example.hello;
    import com.example.util.Hello;
    public class Console {
        public static void main(String [] args) {
         Hello.hello("world!");
    2013-05-25 14:02:55 dpchrist@desktop ~/sandbox/java/jar
    $ cat libs/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-25 14:03:03 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -rf bin ext obj
    mkdir obj
    cd libs; javac -d ../obj com/example/util/Hello.java
    mkdir bin
    cd apps; javac -d ../bin -cp ../obj com/example/hello/Console.java
    cd bin; java -cp .:../obj com.example.hello.Console
    hello, world!
    mkdir -p ext/com/example
    cd obj; jar cvf ../ext/com/example/util.jar com/example/util/Hello.class
    added manifest
    adding: com/example/util/Hello.class(in = 566) (out= 357)(deflated 36%)
    cd bin; java -cp .:../ext/com/example/util.jar com.example.hello.Console
    hello, world!
    2013-05-25 14:03:11 dpchrist@desktop ~/sandbox/java/jar
    $ tree -I CVS .
    |-- Makefile
    |-- apps
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.java
    |-- bin
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.class
    |-- ext
    |   `-- com
    |       `-- example
    |           `-- util.jar
    |-- libs
    |   `-- com
    |       `-- example
    |           `-- util
    |               `-- Hello.java
    `-- obj
        `-- com
            `-- example
                `-- util
                    `-- Hello.class
    19 directories, 6 filesHTH,
    David

  • Problems with CLASSPATH in a executable jar file

    Hi there
    I'm having a problem that I don't know how to solve. My generalq uestion is:
    "Why isn't my CLASSPATH (java.class.path) forwarded into ar unnable class inside a jar file?"
    The situation is:
    I have made a runnable jar file containing an ant build.xml file, a jar file containing some patch files, and a class called AntLoader.class. AntLoader are the file that are executed (inserted into the manifest). This works. The class are executed, but it can't find the package needed for starting ant.
    ant.jar is in my CLASSPATH, and therefore everything works fine if I'm running AntLoader outside the jar file.
    I know that I can use different ClassLoader classes for dynamicly loading of a class, but then I need a path to where ant.jar is located. And then again my system wont be general. The jar file is supposed to be distributed as a system patch to customers. And their location of where ant is installed will not be the same.
    So what I'm looking for is a way to pass my CLASSPATH from my environment on to a jar file. Is that possible?
    running java -classpath "${CLASSPATH}" -jar cpc.jar doesn't help at all. The java.class.path is still set to cpc.jar when I'm executing the AntLoader class inside cpc.jar.
    Can anyone please help me?
    Brgds
    Jakob

    've found the solution to the problem. You have to use the -Xbootclasspath/a parameter when running java.
    Example on unix:
    java -Xbootclasspath/a:${CLASSPATH} -jar test.jar
    Brgds
    Jakob

  • Jar file Corrupted

    Hi
    I created an exe for a jar file using Xenoage.
    The exe file executes fine in normal conditions.
    I used a license manager for my software.
    The input file for the license manager is the exe
    file created by Xenoage.
    The output file obtained is in an unrecognised format. When
    i execute the file using java the error that i get is
    Invalid or corrupt jar file+
    What could be the reason for the jar file to be corrupt.
    with Regards
    A.Rajesh

    >
    I have auser that gets the following error message when he tries to launch my application through Java web start:
    An error occured while launching/running the application.
    Corrupted JAR file at http://javadl.sun.com/webapps/javawsautodl/AutoDL/j2se/javaws-1_0_1-j2re-1_6_0-inst-windows-i586.jar>
    That URL is a 404, it does not exist. Where did it come from? Your JNLP file?
    Speaking of which, where is your JNLP file (URL or content)?
    >
    I have asked to perform the following operations but without any success:
    - re-install the JRE
    - clear the cache of the JWS applications>How about changing the cache location entirely? I describe how on the last post of this thread.
    <http://forum.java.sun.com/thread.jspa?threadID=5209499>
    >
    He gets exactly the same message when trying to execute:
    javaws.exe -viewer >Same deal when launching the player?
    <http://java.sun.com/products/javawebstart/apps/player.jnlp>

  • How does the app know image folder (non class files) wrapped in jar file?

    Hi,
    I created an jar file, client.jar, which wrap all necessary files, including packaged class files ( in a hierarachy structure), image folder, properties folder, and ext folder (containing other jar files used). When I run the jar file, like
    java -classpath c:\tmp\client.jar -jar client.jar
    the app does not know where the images go and could not get the properties files. Actually the image and properties files are contained in the same file: client.jar. How can I fix this. I don't want to extract the jar file back to several separated folders and then run it.
    Appreciate the help.

    Unfortunately you have to make some changes in your code.. to find the pictures you need to replace:
    ImageIcon pic = new ImageIcon("pic.gif");
    with
    URL url = MyClass.class.getResource("pic.gif");
    ImageIcon pic = new ImageIcon(url);
    where MyClass is the class which needs to load the resource.
    I hope this helped you! /Pingu

  • Nested jar files

    two questions:
    1) How can I get access to a nested jar file? That is lets say i have a jar file names "Outer.jar", which includes two jar files. These two inner jar files each have a main method. Example: "Inner1.jar" and "Inner2.jar". How can I run each inner jar file? Is this possible?
    That is: "Inner1.jar" works perfectly fine by itself, if it was the only jar file, and it has it's own main method. The same goes for "Inner2.jar". But, How can I put these two into a main jar file, "Outer.jar", and then run each of the two inner jar files?
    2) Is it possible to make a jar file that contains two jar files both of which have separate main methods?

    It makes a great deal of sense to nest jar files. For example, I'm trying to put together a standalone JavaHelp "document". Wouldn't it be great if my customer could double click on a jar file and have a JavaHelp view open up with the documents inside? This requires bundling a JavaHelp jar, a viewer jar, and the document jar containing the docs and helpset. The only thing the customer needs in a JRE. No fuss, no muss, no messy installation.
    Another situation is where I want to bundle up multiple jar files as one to simplify distribution and deployment.
    --jon
    I've never heard of anyone wanting to do this before
    but:
    1. I think the only way to do this will be to use a
    custom classloader. You could have a runnable class in
    your Outer.jar that launches a custom classloader.
    This custom classloader will load your classes and you
    can call your runnable classes in Inner1.jar and
    Inner2.jar using seperate threads. You need a custom
    classloader because if you launch you .jar from (for
    example) "D:\myJar\Outer.jar" and specify the
    classpath (in the JAR manifest file) to (for example)
    "lib/Inner1.jar" it won't look at the JAR file entry
    "lib/Inner1.jar" it will look in
    "D:\myJar\lib\Inner1.jar". You're going to have
    problems though because you're basically running 3
    programs in 1 JVM. Things like static variables and
    security are going to be an issue. Basically unless
    there is a very good reason to do this, it sounds like
    a bad idea.
    2. Yes.

  • Error JCo starting .jar file

    Dear all,
    I am new to Java, but I try to implement a small application which talks to our SAP. I am working with eclipse 3.3 and I've installed JCO 2.1.8. I modified Example1 a little bit and everything works fine when I start my program within eclipse with run as->java application. I added the sapjco.jar file to the build path of my project. I also added C:\Programme\sapjco-ntintel-2.1.8 to my windows path variable and copied *.dll to system32. When I export my project as a .jar file and try to start it with
    java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. -jar Jco.jar
    I get the error message
    java.lang.NoClassDefFoundError: com/sap/mw/jco/IMetaData
    The contents of my .classpath file is:
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
         <classpathentry kind="src" path="src"/>
         <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
         <classpathentry kind="lib" path="C:/Programme/sapjco-ntintel-2.1.8/sapjco.jar"/>
         <classpathentry kind="output" path="bin"/>
    </classpath>
    But I can start the java program with
    java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. Jco
    when I am in the directory with the .class file.
    Whats wrong with my .jar file?
    Thanks in advance,
    Rolf
    Message was edited by:
            Rolf Winter

    Hi,
    thanks for your answers.
    C:\Programme\sapjco-ntintel-2.1.8 containing sapjco.jar is already added to the path environment variable.
    summary:
    -I installed JCO in folder C:\Programme\sapjco-ntintel-2.1.8
    -I copied *.dll to Windows\system32
    -I added  C:\Programme\sapjco-ntintel-2.1.8 to the path environment variable
    -sapjco.jar is in the building path
    -<i>I can start the "normal Java .class file"</i> with java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. Jco
    -I've created a jar file with the export dialog. I just followed the steps and selected the starting class "Jco".
    -In the directory containing the jar file I tried to start it with the following commands
      java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. -jar Jco.jar
      java -jar Jco.jar
    but I always get the message
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sap/mw/jco/IMetaData
    Any further ideas?
    Rolf

Maybe you are looking for