.Exe inside a .jar

Running a process is easy:
      final Process p = Runtime.getRuntime().exec(path+exe+"  " + args);However a problem exists when the application and the executable get
packaged together in a single jar file.
First I tried something like:
String str = ThisClass.class.getResource(path + exe).getPath() + args;And passing str as the exec argument which still succeeds in but fails outside a
.jar file.
Does anybody know :
a) if this is possible in the first place (it seems logical to be possible)
b) how to do this
thanks

Since no comments have been posted yet. It might be usefull that I give the solution I , used which comes to extracting the .exe from the jarfile. Or from the current location
when working from an IDE.
            File temp = File.createTempFile(tempstring, ".exe");
            final DataInputStream in = new DataInputStream(TriangleGraph.class
                    .getResourceAsStream("the_exe.exe"));
            final DataOutputStream out = new DataOutputStream(
                    new FileOutputStream(temp));After this the contents of the exe can be from in to out. And a process can be
created with
Process p = Runtime.getRuntime().exec(temp.getAbsolutePath() + " " + params);Which solved my problem. Comments on this approach are welcome.

Similar Messages

  • Include and call an .exe file inside my jar file

    Hi.
    I want to include an exe file and call it inside my jar file. this is the code.
    InputStream is = getClass().getResourceAsStream("/native/my.exe");
              int[] line = new int[is.available()];
              File myFile = File.createTempFile("my","exe");
              myFile.deleteOnExit();
              myFile.setExecutable(true);
              FileOutputStream out = new FileOutputStream(myFile.getAbsolutePath());
              int i = 0;
              int c;
              while((c=is.read()) != -1){
                   line=c;
                   i++;
              is.close();
              for(int j= 0;j<line.length;j++)
                   out.write(line[j]);
              out.close();
    So i store it in my temp folder. Than i run
    String myFileLocation = myFile.getAbsolutePath();
    p = rt.exec(myFileLocation);
    Everything goes fine, but the behaviour of the .exe file is not the same. I mean when i run the commands
    PrintWriter writer = new PrintWriter(p.getoutputStream());
    writer.println("command");
    the behaviour is not the same. What goes wrong.

    But to load the xml file I need to create a File objectIf this is true then you will not be able to load the XML file, since a jar entry is not a File object and cannot be represented as one.
    However if you get rid of whatever it is that loads your XML file and replace it by more standard JAXP processing, you should be able to parse an InputStream that reads from the jar entry. You know how to get that so it should not be a problem.

  • Exec exe file in jar

    Hi,
    Is there a way to execute an exe file that is inside the jar with the main class?
    Right now, I am copying the file to a folder, and executing it.
    Thanks

    Would be a great security risk...
    Not possible.

  • Including exe in a jar

    hi,
    i want to include a .exe in a jar,how do i di it..actualy what my code does is that it calls a exe from inside which i have saved somewhere else..what i want is to get this exe included in jar so that i wil not have to save it newhere else..is it possible..
    plz try help..

    I would reply to that but I'll just stick with what
    you gave me..... thx for replying anyway, at a first
    look it seems as if I didn't specify the search
    pattern anough to get a good score when seraching....
    well thx for replyingDon't take it personally, this question has just been answered many times lately. I didn't feel like doing it again.

  • Help Needed - Executing a .exe in a JAR

    Hi,
    I am stuck with a problem...
    I have a jar file which has an applet class, a .exe file and a .txt file.
    I want the applet to call the exe which will use the .txt and produce two more .txt files(inside the jar)..
    Is it possible?
    Thanks,
    Bharath

    I want to run my applet from the web. But the applet should call a exe (which takes in a txt as a input) and generate a couple of txt's.....
    To make my applet execute the .exe i had to make it into a signed jar....so now how do i do it without putting the .exe also into the jar?
    Is there any other way?
    Thanks
    Bharath

  • How to make an applet to read the Text file present inside a jar

    Hi All,
    I have writen one applet named ReadFile.java which reads a text file present in the same directory and does some manipulation of text file contents.
    The applet code runs successfully when i run the applet in command prompt like
    {color:#ff0000}*java ReadFile*{color}
    And i am getting the needed results.
    Then i made a jar file with the applet code and text file as
    {color:#ff0000}*jar cvf rf.jar ReadFile.class File1.txt*{color}
    Then i have inlcuded this applet inside a html file as
    {color:#ff0000}*<applet code= "ReadFile.class" width= "500" height= "300" archive = "rf.jar" ></applet>*{color}
    after this when i load the html file, the applet code is not executed fully. Its throwing FileNotFoundException: File1.txt.
    Applet is not recognizing trhe text file present inside the jar file.
    Can any body explain me how to overcome this problem. Any setting needs to be done for making the applet indicate the presence of Text file inside the jar file.

    what code in your applet gets the text file and reads it? are you using getResource or something similar?

  • How can i get the path to config folder placed inside the jar file?

    Hi i have developed an RCP application using eclipse.
    In my application config directory is there.
    When i export my RCP application as JNLP Project the jar file is created which contains config folder inside it.
    When i download the application using java web start , how can i get the path to config folder placed inside the jar file?
    Will the config folder exists in local cache in my system?
    Help needed.
    -Deepak

    -- This works in CS6:
    tell application "Adobe InDesign CS6"
      set myDocument to active document
      set selectedRectangles to selection of myDocument
      set theGraphicsLink to file path of item link of (graphic 1 of (item 1 of selectedRectangles))
    --> "Macintosh HD:folder/folder/filename.tif"
    end tell

  • JRE doesn't find the main class inside a JAR archive file

    Hello everybody,
    I've written a small application in Java, using NetBeans. Running my application inside NetBeans works fine, but I can't run it from the console or by double clicking the jar file.
    Running it from the console I get the following error message:
    java -jar TestApplication.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: tst.Benchmark
       at gnu.java.lang.MainThread.run(libgcj.so.81)
    Caused by: java.lang.ClassNotFoundException: tst.Benchmark not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:TestApplication.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
       at java.net.URLClassLoader.findClass(libgcj.so.81)
       at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.81)
       at java.lang.ClassLoader.loadClass(libgcj.so.81)
       at java.lang.ClassLoader.loadClass(libgcj.so.81)
       at gnu.java.lang.MainThread.run(libgcj.so.81)I know that these errors often come when the class path is not set in the right way, and using a single java file, you can fix this by passing the parameter "-cp ."
    I tried this with the jar file but it does not work and using "-cp TestApplication.jar tst/Benchmark" didn't work either.
    Inside the jar file I have the META-INF Folder and a "tst" Folder which contains all my class files. And I've set tst.Benchmark as the main class, this also stands in the manifest file correctly.
    Do you have any ideas what could be wrong?
    Greetings JavanianGuy

    This line
    at gnu.java.lang.MainThread.run(libgcj.so.81)says that you're using GNU's Java, not Sun's Java. They are not the same. GNU Java is incomplete.
    You'll need to ask this question at the GNU Java site.
    Recommendation: Use Sun's Java

  • Running a batch file inside a jar

    HI all
    I created a jar file , in which i need to run a batch file , so i wrote a main class to execute the run the batch file , but when iam running the jar it is searching for the given batch file out side the jar.
    my code is some thing like below
         public static void main(String args[])
              try
                   Runtime rt=Runtime.getRuntime();
                   Process process=rt.exec("%DIRNAME%/start.bat");
       InputStreamReader reader =
                      new InputStreamReader ( process.getInputStream () );
                   BufferedReader buf_reader =
                       new BufferedReader (  reader );
                    String line;
                    while ((line = buf_reader.readLine ()) != null)
                                 System.out.println (line);
              catch (IOException e) {
                    System.out.println (e);
         }so please help me.. is it the problem in specifing the path...?
    are does it have any other method to read the stream functions ..
    thanks in advance
    sam

    I don't think this will work. You could not go to a command line and enter, "%DIRNAME%/start.bat" if start.bat was inside a jar - the CLI doesn't know how to read a batch file inside a jar.
    I think it would work to programmatically read the lines of start.bat (when it is inside the jar) into an array of Strings and use Runtime.exec with the array as the argument.
    It would also work to extract the start.bat file, then execute it using Runtime.exec.

  • Call class inside a jar file??

    Hello group,
    I have a class with a main mathod and this class is inside a .jar file. This jar file reside under my
    web-inf\lib or class-path directory in my application at Weblogic Server.
    How can I call this class by command line?
    I have to create a cliente to do it?
    Is it possible? I´m having problems because the weblogic server is using the jar file at the same time that I trying use it calling by command line.
    Where can I find more information?
    Message was edited by:
    Denimar

    Authcloud9981 wrote:
    Hi I have an executible JAR file that I can call from command line by using the command - "java -jar file.jar".
    Is there a way for me to call this JAR file inside a Java class in another Java Program?There can be more going on in a jar than just as a container for classes.
    The manifest defines the behavior. So to replicate the behavior you must do exactly that.
    As an example of that.
    [http://java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html#download]
    Additionally by running it in your application you must consider what the scope of that is. If you just load the classes directly then they will be in the system class loader and thus cannot be unloaded. Using a class loader solves that.

  • JARs inside my JAR

    Hi Folks,
    I'm creating a JAR file for my application. My app uses another JAR file and I want to package it inside my jar.
    I tried to use "Path-Class" attribute in MANIFEST.MF file but without success.
    Any help would be appreciate.
    TIA.
    Romualdo Rubens de Freitas

    I wonder how you missed to recognize that jars DO contain jars for four years, as you subscribed in 2001.
    Of course the standard class loader cannot handle jars in jars, but many solutions do exist for this problem. (It was really a problem, since almost all java applications are required to ship with jars inside jars).
    The best solution I encountered, is the fat_jar plugin for eclipse. If you are not an eclipse user try ONEJar.
    Being silent is sometimes better than to provide non-solutions for problems for which solutions exist.

  • Applet inside a JAR: Cannot access other classes within the JAR

    Hello,
    Description
    Web app + applet (packaged in a JAR)
    I have followed this tutorial
    JAR contents
    package mypackage
    SimpleApplet.class
    SimpleObj.class
    _"SimpleApplet" uses "SimpleObj"_
    package mypackage;
    public class SimpleApplet extends JApplet {
        @Override
        public void init() {
            SimpleObj obj = new SimpleObj();
    HTML code
    <applet archive="SimpleApplet.jar" codebase="." code="mypackage.SimpleApplet.class" width="800" height="600" />
    SimpleObj cannot be found (Java Console)
    java.lang.NoClassDefFoundError: mypackage/SimpleObj
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: mypackage.SimpleObj
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 8 more
    Caused by: java.io.IOException: open HTTP connection failed:*http://localhost:8080/SimpleApp/mypackage/SimpleObj.class*
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 12 more
    Exception: java.lang.NoClassDefFoundError: mypackage/SimpleObj
    It looks like JRE does not search for the SimpleObj class inside the JAR, but tries to get it from the server...
    Any ideas?
    Thanks in advance,
    Gerard
    Edited by: gsoldevila on Dec 10, 2008 2:05 AM

    misread, deleted
    Edited by: atmguy on Dec 10, 2008 1:12 PM

  • A .dll inside a .jar file

    Hello,
    I want to place a .dll inside a .jar file ? It's possible, What is the library.path setting: the jar file or the path where the dll is put is in the jar file; and the argument of the System.loadLibrary?
    Thank for all

    Hello,
    I want to place a .dll inside a .jar file ? It's
    possible,Of course, you can put any type of file you want into a jar file.
    What is the library.path setting: the jar
    file or the path where the dll is put is in the jar
    file; and the argument of the System.loadLibrary?You cannot do a System.load() or System.loadLibrary() on something in a jar file.
    You have to first extract the dll to the filesystem. Then if you put it in the library path you can use System.loadLibrary(). But I think it is easier to use System.load() as you know the complete path to where you put the dll and can just supply that to System.load().

  • Java Files inside the jar file cannot be read or accessed through Eclpse

    The Java File inside the jar file of the eclipse cannot be accessed through the Eclipse . It shows error for the modules in the jar file .
    But when compiled with adding the jar files to the class path the compilation is successful .
    How can i browse through the files in the jar like going into the function definition .
    TIA ,
    Imran

    Open MPlayer OSX and show the playlist (command-shift-p) then drag the file into the playlist. Click the file in the playlist and click the "i"nfo button. What does it list for file, video and audio format?
    Not all of the codecs used in avi and wmv files are available for OS X so I'm guessing your file happens to be using one that isn't...

  • Changing values in property file inside a jar in an ear

    Hi,
    I have an application that contains EJB. The environment values needed for initial context of the ejb is kept in a .properties file. I have created an ear of the application. Inside the ear there is a jar which contains the .properties file. I need to deploy the ear to different environments. However before deploying I need some kind of script to change the values in the .properties file inside the jar in the ear.
    Can anyone provide some help/pointers about how can I achieve it (Using ANT/WLST)

    WLST does not have any capability to update a JAR.
    WLS 10.3 (still in tech preview) has the ability to override properties
    files inside the jar with an external properties file. This would allow you
    to deploy the same ear to different environments, and then only deploy a
    different properties file in the plan directory.
    <Rishi Shah> wrote in message news:[email protected]..
    Hi,
    I have an application that contains EJB. The environment values needed for
    initial context of the ejb is kept in a .properties file. I have created an
    ear of the application. Inside the ear there is a jar which contains the
    .properties file. I need to deploy the ear to different environments.
    However before deploying I need some kind of script to change the values in
    the .properties file inside the jar in the ear.
    Can anyone provide some help/pointers about how can I achieve it (Using
    ANT/WLST)

Maybe you are looking for

  • How to connect my ipad2 to apple tv the first time

    Having trouble connecting iPad 2 to apple tv.

  • Connecting to a SOAP web Service

    For my sapp I want to connect to a simple web service . This web service has Several functions .They each accept some arguments and return End result.. The web service is being activated but it always returns an answer of zero (NULL ) which makes me

  • Workitem is not removed from User Inbox

    Hi, There is requirement, when the PR is created by user, first it has to go his department Head and then to Manager, AGM, GM, etc. There are different departments. I'm maintaining organizational structure and giving positions in Release Strategy. No

  • Blocks behaving differently.

    Hi, DB 9.2.0.1. I am running the following anonymous block, but it's not executing the way, it should. Like I am assigning create table privililege by executing this block , according to me it should executed, but when I run this, the control takes i

  • How can I fill a JComboBox with a ResultSet?

    I want to fill a JComboBox with the data in ResultSet. What�s the better way to do this? Can I convert a RecordSet to a Vector and use the vector in JComboBox constructor? Thanks for any help. Renato