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.

Similar Messages

  • How to include and call exe file in jar?

    Hi, I am writing a Java application that calls an external exe file to accomplish some tasks. In order to make the program more user friendly, I would like to package the Java application and the exe file into one JAR file and distribute that JAR file to users. I tried to package all these files by running the following command:
    jar cmf manifest.txt java_class_file exe_fileThe manifest.txt contains only the following entry:
    Main-Class: java_class_fileHowever, when I execute the program with java -jar bundle.jar, the JVM complains that it cannot find the exe file. (Everything works fine when I run the original class file with java)
    Would anyone kindly teach me how to do this?
    Thanks in advance!

    You cannot call an exe file in a jar.
    You can have the jar unpack the exe and then run it however.

  • I want to uninstall and then reinstall Firefox but I can't uninstall it. Nothing happens when I click remove in program access and defaults and the helper.exe file in the firefox uninstall dir doesn't do anything either.

    I want to uninstall and then reinstall Firefox but I can't uninstall it. Nothing happens when I click remove in program access and defaults and the helper.exe file in the firefox uninstall dir doesn't do anything either.

    "program access and defaults" is not the place to remove programs in Windows. You need to go to the control panel and click on Add and Remove programs. For instructions on how to uninstall Firefox, see [[Uninstalling Firefox]]

  • HT2305 I downloaded, and have two .msi files and one setupadmin.exe file. I click the latter and nothing happens?

    I downloaded 2 updates (download only), and there's two  .msi files and one setupadmin.exe file. I click the latter and nothing happens? How am I meant to do install these updates?

    Sorry I forgot to mention I was doing this on a PC with Vista (the heading was Windows so I didn't bother to mention this). Anyway by trial and error I found that you can click on the .msi files to install them. The files were downlads of updates to iTunes and iCloud Control Panel.

  • I have downloaded the Premiere 10 trial and run the exe file in...\Adobe Premiere Elements 10\PRE 10

    I have downloaded the Premiere 10 trial and run the exe file in...\Adobe Premiere Elements 10\PRE 10\ElementsSTIInstaller, However, I can not find the program on my computer.  Can you please tell me the procedure to install the program following the down load???
    P.S. the download assistant does not install the program automatically and I have restarted the computer.
    Thankyou

    this might help:
    http://helpx.adobe.com/photoshop-elements/kb/install-premiere-elements-photoshop-elements. html

  • Is it possible to convert Java to EXE and run this EXE file without any JRE

    hello friends
    I have GCC/GCJ for windows but dont know how to work with it... it creates file with .o extension but i m not able to create .exe from that... i installed mingw for that also .. unsuccessful ...
    tell me the solution for it... i want to generate machine dependent exe from java file...on the web i ve seen that GCC/GCJ is used on linux platform..not cleared properly..
    Again i m writing my question
    Is it possible to convert Java to EXE and run this EXE file without any JRE if yes then how... tell me the procedure to do that...

    Vipul wrote:
    Its software now hardware .... some times u need these things ...anyway do u ve solution for my questionSo what? By creating a native executable you are restricting the program to the OS for which that native executable was made, just like removing the engine from a car restricts driving to downhill only. So like the I said, the principle remains the same, "Why would you want to?"
    I am asking you, truthfully, why do you feel the need to negate the largest advantage of using Java by creating a native executable from it?
    What is your rationale?
    I can pretty much guarantee there is a much better way of achieving your wish without "removing the engine".

  • How do I call another exe file from a Java program?

    Hi,
    I am doing a simple IDE (text editor/interpreter) for a simple programming language we are developing. It will be submitted as our project for this semester. I created an exe file (in C) which will be used as the interpreter. How do I call the interpreter from my IDE? The interpreter should run when the user clicks a button (i.e. the "Run" button). I've tried the Java Runtime class but it doesn't work. Anyone who knows how to do it?
    Thanks!

    I first tried to do a simple program that calls system commands such as dir, cd <dir>, etc.
    I do not have the exact code right now but as far as I can remember, here's what I wrote:
    class Sample{
        public static void main(String args[]) throws IOException{
           BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
           String command;
           while ((command = in.readLine()).equalsIgnoreCase("exit") == false){
              try{
                Runtime.getRuntime().exec(command);
              }catch(Exception e){
                 System.err.println("Error: " + e);
          System.exit(0);
    }

  • Can you call external exe file from Flex Air Application like notepad.exe

    Im trying to make my Air Application open an External exe file anyone know if this can be done?

    Hi,
    If you want to share code between a flex app and AIR, you
    could isolate the common bits as a swc file and link to the swc
    from both the flex and air project.
    Also, you could have the flex mxml file and air mxml file
    load the same module (which has the same stuff as your original
    flex application) using ModuleLoader.
    Or, you could even load the swf of your flex application
    using SWFLoader in your air mxml file.
    Basically, check out creating flex libraries, modules and
    runtime loading of swfs.

  • Call the exe file

    Hello Friend
    I am using apex 3.1.
    I want to click on the button then call the webcam exe file.it is possible in oracle apex.
    regard
    vikas nagawade

    Hi,
    I think you have ask similar question before
    It's possible to attach scanner machine
    Did you try search on this forum?
    Naviagation Bar Entries: Adding a link that Runs a local program (OSK.EXE)
    Regards,
    Jari

  • Need urgent help. Calling of exe files from java program

    This program can execute small .exe files that donot take inputs but doesn't work for exe files that takes input. what could be the problem.
    Server code :-
    import java.io.*;
    import java.net.*;
    public class Server1 {
         private Player[] players;
         private ServerSocket server;
         private ExecHelper exh;
         String command = null;
         String message = null;
         public Server1() {
              players = new Player[5];
              try {
                   server = new ServerSocket( 12345, 5 );
                   System.out.println("Server started...");
                   System.out.println("Waiting for request...");
              catch( IOException ioe ) {
                   ioe.printStackTrace();
                   System.exit( 1 );
         } //end Server constructor
         public void execute() {
              for( int i = 0; i < players.length; i++ )
              try {
                   players[i] = new Player( server.accept() );
                   players.start();
              catch( IOException ioe ) {
                   ioe.printStackTrace();
                   System.exit( 1 );
         public static void main( String args[] ) {
              Server1 ser = new Server1();
              ser.execute();
              System.exit( 1 );
         private class Player extends Thread {
              private Socket connection;
              private ObjectOutputStream output;
              private ObjectInputStream input;
              public Player( Socket socket ) {
                   connection = socket;
                   try {
                        input = new ObjectInputStream( connection.getInputStream());
                        output = new ObjectOutputStream( connection.getOutputStream());
                        output.flush();
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
                        System.exit( 1 );
              public void run() {
                   try {
                        message = "Enter a command:";
                        output.writeObject( message );
                        output.flush();
                        do {
                             command = ( String ) input.readObject();
                             String osName = System.getProperty( "os.name" );
                             String[] cmd = new String[3];
                             if( osName.equals( "Windows 2000" )) {
                                  cmd[0] = "cmd.exe";
                                  cmd[1] = "/c";
                                  cmd[2] = command;
                             else if( osName.equals( "Windows NT" ) ) {
                             cmd[0] = "cmd.exe" ;
                             cmd[1] = "/C" ;
                             cmd[2] = command ;
                             Runtime rt = Runtime.getRuntime();
                             Process proc = rt.exec( cmd );
                             exh = new ExecHelper( proc, output, input);
                        } while( !command.equals( "TERMINATE" ) );
                   catch( Throwable t ) {
                        t.printStackTrace();
         } //end class Player
         public class ExecHelper implements Runnable {
         private Process process;
         private InputStream pErrorStream;
         private InputStream pInputStream;
         private OutputStream pOutputStream;
         private InputStreamReader isr;
         private InputStreamReader esr;
         private PrintWriter outputWriter;
         private ObjectOutputStream out;
         private ObjectInputStream in;
         private BufferedReader inBuffer;
         private BufferedReader errBuffer;
         private Thread processThread;
         private Thread inReadThread;
         private Thread errReadThread;
         private Thread outWriteThread;
         public ExecHelper( Process p, ObjectOutputStream output, ObjectInputStream input ) {
              process = p;
              pErrorStream = process.getErrorStream();
              pInputStream = process.getInputStream();
              pOutputStream = process.getOutputStream();
              outputWriter = new PrintWriter( pOutputStream, true );
              in = input;
              out = output;
              processThread = new Thread( this );
              inReadThread = new Thread( this );
              errReadThread = new Thread( this );
              outWriteThread = new Thread( this );
              processThread.start();
              inReadThread.start();
              errReadThread.start();
              outWriteThread.start();
         public void processEnded( int exitValue ) {
              try {
                   Thread.sleep( 1000 );
              catch( InterruptedException ie ) {
                   ie.printStackTrace();
         public void processNewInput( String input ) {
              try {
                   out.writeObject( "\n" + input );
                   out.flush();
                   catch( IOException ioe ) {
                   ioe.printStackTrace();
         public void processNewError( String error ) {
              try {
                   out.writeObject( "\n" + error );
                   out.flush();
         catch( IOException ioe ) {
                   ioe.printStackTrace();
         public void println( String output ) {
              outputWriter.println( output + "\n" );
         public void run() {
              if( processThread == Thread.currentThread()) {
                   try {
                        processEnded( process.waitFor());
                   catch( InterruptedException ie ) {
                        ie.printStackTrace();
              else if( inReadThread == Thread.currentThread() ) {
                   try {
                        isr = new InputStreamReader( pInputStream );
                        inBuffer = new BufferedReader( isr );
                        String line = null;
                        while(( line = inBuffer.readLine()) != null ) {
                                  processNewInput( line );
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
              else if( outWriteThread == Thread.currentThread() ) {
                   try {
                        String nline = null;
                        nline = ( String ) in.readObject();
                        println( nline );
                   catch( ClassNotFoundException cnfe ) {
                   //     cnfe.printStackTrace();
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
              else if( errReadThread == Thread.currentThread() ) {
                   try {
                        esr = new InputStreamReader( pErrorStream );
                        errBuffer = new BufferedReader( esr );
                        String nline = null;
                        while(( nline = errBuffer.readLine()) != null ) {
                             processNewError( nline );
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
    Client code :-
    // client.java
    import java.io.*;
    import java.net.*;
    public class Client {
         private ObjectOutputStream output;
         private ObjectInputStream input;
         private String chatServer;
         private String message = "";
         private Socket client;
         public Client( String host ) {
              chatServer = host;
         private void runClient() {
              try {
                   connectToServer();
                   getStreams();
                   processConnection();
              catch( EOFException eofe ) {
                   System.err.println( "Client terminated connection ");
              catch( IOException ioe ) {
                   ioe.printStackTrace();
              finally {
                   closeConnection();
         } //end method runClient
         private void connectToServer() throws IOException {                                                                 
              System.out.println( "Attempting connection...\n");
              client = new Socket( InetAddress.getByName( chatServer ), 12345);
              System.out.println( "Connected to : "+ client.getInetAddress().getHostName());
         private void getStreams() throws IOException {
              output = new ObjectOutputStream( client.getOutputStream());
              output.flush();
              input = new ObjectInputStream( client.getInputStream());
         private void processConnection() throws IOException {
         while( true ){
                   try {
                        message = ( String ) input.readObject();
                        System.out.print( message );
                        InputStreamReader isr = new InputStreamReader( System.in);
                        BufferedReader br = new BufferedReader( isr );
                        String line = null ;
                        line = br.readLine();
                             output.writeObject(line);
                             output.flush();
                   catch( ClassNotFoundException cnfe) {
                        System.out.println( "\nUnknown object type received");
         } //end processConnection
         private void closeConnection() {
              System.out.println( "\nClosing connection");
              try {
                   output.close();
                   input.close();
                   client.close();
              catch( IOException ioe ) {
                   ioe.printStackTrace();
         public static void main( String args[] ) {
              Client c;
              if( args.length == 0 )
                   c = new Client( "127.0.0.1" );
              else
                   c = new Client( args[0] );
              c.runClient();

    maybe you should
    1. Use code tags so the posted code is understandable
    2. Stop marking your post urgent, that just puts peoples backs up
    3. Stop posting the question every couple of hours on every imaginable forum.. Post it once and start a single dialog

  • How to call an EXE file on a remote system from SAP system?

    Hi Friends,
    I want to execute an EXE file existing on the remote system from SAP system. Could some one give me an idea of how to execute that?
    Thanx in advance,
    Ram

    Hi Ram,
    Try this
    SXPG_COMMAND_EXECUTE
    Reward if this helps,
    Satish

  • QT7 gives codec update error and starts downloading .exe file on a Mac...

    I have problems playing some .mov files on my Mac with QT X, it says I need QT 7 so I installed that, but then QT 7 comes up with an error: codec needs updating and it starts to download QuickTimeupdateKB337585.exe
    I have Perian, Flip4Mac installed and also divx and xvid components in the /Library/Quicktime folder. How can I find out what codec I'll need and how do I install it in the QT 7 folder?

    CS2 would run on older Macs.  What are your system and OS specs like?
    PowerPC® G3, G4, or G5 processor
    Mac OS X v.10.2.8 through v.10.3.8 (10.3.4 through 10.3.8 recommended)
    320 MB of RAM (384 MB recommended)
    750 MB of available hard-disk space
    1,024 x 768 monitor resolution with 16-bit graphics adapter
    CD-ROM drive
    Internet or phone connection required for product activation
    Gene

  • I'm running windows 7, downloaded firefox 3.6, when I click to open and run the exe file, it says the file is corrupt. Any thoughts? I have the latest Adobe Flash Player installed

    Says file is corrupt every time I try to install Firefox 3.6

    Hi Raphe,
    There are a couple of things I know that can cause this. One of which I have experienced myself.
    Sometimes, your router may be faulty. This will usually effect all downloads unless they are very small files. I have experienced this myself, and found the only way to fix the problem is to replace it.
    Another problem that could cause this is a virus. You should scan your computer for viruses using a trusted antivirus. The virus is sometimes scareware which claims you have a virus, but actually, the only virus is the scareware antivirus!
    I hope this helps,
    -Taddle

  • Saving images on my database and calling the open file dialog

    i want to be able to save image in my database or alternatively save them on a file system. meanwhile i want to allow them choose the name of the image in the folder by using the win_api_dialog.open_file. My platform is win2000. do i need to add any other thing to this like a particular library or just anything. please i need this help urgently.database os is unix ware.

    Hello,
    You can do this without using library. Suppose you have a table with BLOB data type column and one form which has image box to display and store image boxes.
    Now by using READ_IMAGE_FILE read picture file. To write picture to file use WRITE_IMAGE_FILE. and
    if you want to give users open file dialogue box then use GET_FILE_NAME builtin.
    All the best.
    Adinath Kamode

  • Using Parallels 9 and WIndows 7, .exe files won't launch

    I have tried everything I can think of.
    When I double click the .exe (from mac or windows makes no difference) I get an "open with" window listing mostly mac programs to try to launch it with.  Need help. 

    Check here:
    Virtual Machine > Configure > Options > Sharing > make sure Shared Profile is checked.
    also
    Virtual Machine > Configure > Options > Applications > make sure Share Windows Applications with Mac is checked.

Maybe you are looking for

  • Product Invalid Error while creating ASN

    Hi I am trying to create ASN by navigating from DCM screen but in Create ASN screen shows error as "Product Invalid". When I check in Product  field help, pop up does not show this product although product is visible on DCM screen. I checked all mast

  • Inserting an automatic Date and Time

    Hello Everyone, Thanks for all the help in the past. I own a couple of summer rental duplexes at the Jersey shore and basically use my website as an advertising billboard of pictures. On my "Availability and Rates" page, I display a calendar with my

  • "Ask for Finder Items" Automator action broken?

    OK, I'm pulling my hair out on Automator (again). I'm on OS X Lion 10.7.1. Here's what I want to do: I have image files named "something-something (S1).png" and I want to create a copy of each file named "something-something (S2).png" then resize tha

  • IOS 8 nightmare do not download it.

    after downloading iOS 8 my ipad2 is a nightmare to use?? Slow to respond, constantly crashing, shutting down Apps while I am using them, tried to print boarding passes today was impossibl??? I'v lost loads of info from my docs and bookmarks to name j

  • Get DDL for uncrypted packages using DBMS_METADATA

    Hi all, i was wondering if i could extract DDL sources for only uncrypted packages in my database using DBMS_METADATA? i have a lot of crypted packages stored in the DB. thank you in advance for your help