Can i load and run  .exe file from jar file??

I generated a .jar file witch contain an executable (.exe file) under a directory called 'exec'. I can't execute this exe file using
URL urlExecutable = DlgueLancement.class.getResource("/exec/myPrograme.exe");

import java.io.*;
import java.util.jar.*;
import java.util.zip.*;
public class Extracter
    public static File extract(File archive, String filename, File target) throws IOException, ZipException
        if( archive == null )
            throw new IllegalArgumentException("Null archive file");
        if( !archive.exists() )
            throw new IllegalArgumentException("Specified archive does not exists");
        if( !archive.isFile() )
            throw new IllegalArgumentException("Specified archive file is not a file");
        if( filename == null )
            throw new IllegalArgumentException("Null filename");
        if( filename.length() == 0 )
            throw new IllegalArgumentException("Empty filename");
        if( target == null )
            throw new IllegalArgumentException("Null target");
        if( target.exists() && file.length() > 0 )
            throw new IllegalArgumentException("Target file already exists and cannot be overwritten");
        JarFile jar_archive = new JarFile(archive);
        ZipEntry entry      = jar_archive.getEntry(filename);
        if( entry == null )
            return null;
        InputStream istream = null;
        FileOutputStream ostream = null;
        try
            istream = jar_archive.getInputStream(entry);
            if( istream.available() == 0 )
                return null;
            byte[] buffer = new byte[istream.available()];
            istream.read(buffer);
            ostream = new FileOutputStream(target);
            ostream.write(buffer);
            return target;
        finally
            if( istream != null )
                try{istream.close();}catch(Exception e){}
            if( ostream != null )
                try{ostream.close();}catch(Exception e){}
}

Similar Messages

  • How do I load and run a sequence from the Tools menu?

    If I can build a sequence to do something special, what's the syntax required to load and run it from a menu? This must be transparent to the customer. I know how to add menu items, but the tools customize window seems to be looking for an exe.

    When you go to tools>>customise and then add in an item to appear in a menu, you need to select sequence, rather than command.
    Hope that helps
    S.
    // it takes almost no time to rate an answer

  • 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

  • How to list files from .jar file in applet?

    I have created applet and export all files to .jar file.
    I use File.list() method in applet to list files from one directory and that works ok but if I try to do that from web browser it sends exception AccessDenied meaning that File.list() isn't allowed in browser.
    I know what's the problem but I don't know how to solve it.
    What I want is to read from directory list of files.
    Help anyone?

    I will post here my code so that can be seen what I want to do:
    import java.awt.BorderLayout;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URLClassLoader;
    import java.nio.charset.Charset;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    import javax.swing.JTextPane;
    public class test extends JApplet {
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         private JTextPane jTextPane = null;
          * This is the xxx default constructor
         public test() {
              super();
          * This method initializes this
          * @return void
         public void init() {
              this.setSize(449, 317);
              this.setContentPane(getJContentPane());
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(new BorderLayout());
                   jContentPane.add(getJTextPane(), BorderLayout.CENTER);
              return jContentPane;
          * This method initializes jTextPane     
          * @return javax.swing.JTextPane     
         private JTextPane getJTextPane() {
              if (jTextPane == null) {
                   jTextPane = new JTextPane();
              return jTextPane;
         public void start(){
              File fileDir= new File("somedirectory");
              String strFiles[]= fileDir.list();
              String a="";
              for(int i =0;i<strFiles.length;i++){
                   a=a+strFiles;
              this.jTextPane.setText(a);
    Method init() is irelevant, it just adds JTextPane in applet.
    Method start() is relevant, it runs normaly when started from Eclipse but from browser it sends exception AccessDenied.

  • 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.

  • Failed to load main-class manifest attribute from jar files....

    Hi,
    I installed Java1.5 version in my system before to that Java1.6 was installed and uninstalled. When i i double clicked on any jar file getting a message like: Failed to load main-class manifest attribute from<name of the jar file>.jar file....
    can anyone please suggest me how to rectify this error.

    mvnath wrote:
    The jar files are worked before the installation of 1.5 but not after installation of 1.5I am guessing that the Windows file association for .jar somehow got munjed. It's hard to say since you have not provided much information.

  • Accessing files from jar file when running application?

    I have an application that when run should read an xml file (test.xml) from a jar file located in a resource folder. I do this:
        File f = null;
        URL url = this.getClass().getClassLoader().getResource("test.xml");
        try {
          f = new File(url.getPath());
    //      f = new File(url.toURI());
        } catch (Exception e) {
          throw new GeneratorException("Preload input not found!");
        }The file is found in the jar but when I want to use it I get problems:
    when doing:
    f = new File(url.getPath());
    this file is not found and when doing:
    f = new File(url.toURI());
    I get and:
    URI is not hierarchical exception
    Is there now way to convert the xml file in the jar file to a File object?

    fedevaps wrote:
    But is there now otherway to create a File from the URL?Only if the URL refers to a file in the first place. Which it doesn't when the URL refers to an entry in a ZIP file because an entry in a ZIP file is not a file.
    java.io.File refers to physical files in the sense that the operating system uses it. It can't refer to Files on remote machines, it can't refer to "files" stored in .ZIP files and it can't refer to some random String that you construct.
    Usually when you think you need a File object in Java, you don't actually need it. There are only a handful of operations that you can do with a File object that can't be done with a URL as well (deleting, renaming are two that come to my mind). Reading from it and writing to it works with a File as well as with an URL.

  • Re: Can't load web app that has sealed jar files

              I forgot to mention that I'm using WebLogic Server 6.1 with
              J2EE 1.2 Plus Additional J2EE 1.3 Features.
              Barry
              "Barry" <[email protected]> wrote:
              >
              >I am getting the error "String index out of range: -1" thrown by
              >weblogic.servlet.internal.WebAppHelper.resolveManifestName when I start
              >WLS. The
              >problem seems to be
              >with certain jar files in the WEB-INF\lib directory of a particular web
              >app. It
              >seems that if the manifest in a
              >jar file has "Sealed: true", the error occurs. If I remove sealed jars
              >from the
              >lib directory, the problem goes
              >away. The jars in question are xalan.jar and crimson.jar.
              >
              >Any ideas?
              >
              >Thanks,
              >Barry
              >
              

    Yes, it's valid.
              Joe Carew wrote:
              > I can't find any reference to CR064391 on the support site. Does anyone know if this
              > is the valid CR number? I am having this same issue trying to deploy axis.
              >
              > Rajesh Mirchandani <[email protected]> wrote:
              > >contact [email protected] and refer to CR064391.
              > >
              > >Barry wrote:
              > >
              > >> I forgot to mention that I'm using WebLogic Server 6.1 with
              > >> J2EE 1.2 Plus Additional J2EE 1.3 Features.
              > >>
              > >> Barry
              > >>
              > >> "Barry" <[email protected]> wrote:
              > >> >
              > >> >I am getting the error "String index out of range: -1" thrown by
              > >> >weblogic.servlet.internal.WebAppHelper.resolveManifestName when I start
              > >> >WLS. The
              > >> >problem seems to be
              > >> >with certain jar files in the WEB-INF\lib directory of a particular web
              > >> >app. It
              > >> >seems that if the manifest in a
              > >> >jar file has "Sealed: true", the error occurs. If I remove sealed jars
              > >> >from the
              > >> >lib directory, the problem goes
              > >> >away. The jars in question are xalan.jar and crimson.jar.
              > >> >
              > >> >Any ideas?
              > >> >
              > >> >Thanks,
              > >> >Barry
              > >> >
              > >
              > >--
              > >Rajesh Mirchandani
              > >Developer Relations Engineer
              > >BEA Support
              > >
              > >
              Michael Young
              Developer Relations Engineer
              BEA Support
              

  • Can't load web app that has sealed jar files

              I am getting the error "String index out of range: -1" thrown by
              weblogic.servlet.internal.WebAppHelper.resolveManifestName when I start WLS. The
              problem seems to be
              with certain jar files in the WEB-INF\lib directory of a particular web app. It
              seems that if the manifest in a
              jar file has "Sealed: true", the error occurs. If I remove sealed jars from the
              lib directory, the problem goes
              away. The jars in question are xalan.jar and crimson.jar.
              Any ideas?
              Thanks,
              Barry
              

              I am getting the error "String index out of range: -1" thrown by
              weblogic.servlet.internal.WebAppHelper.resolveManifestName when I start WLS. The
              problem seems to be
              with certain jar files in the WEB-INF\lib directory of a particular web app. It
              seems that if the manifest in a
              jar file has "Sealed: true", the error occurs. If I remove sealed jars from the
              lib directory, the problem goes
              away. The jars in question are xalan.jar and crimson.jar.
              Any ideas?
              Thanks,
              Barry
              

  • Deleting file from .jar file

    I m having trouble with the Forum search, so sorry if this question has been answered before in this forum.
    If I create a .jar (or an .ear) file, then open the file using Winzip and then delete a file from the zip, does it corrupt the .jar file? I ran into such a problem recently where I could not deploy the application because the .ear file still contained references to the deleted file.

    No, Winzip doesn't corrupt jar files. But if you have something else that expects to find X in the jar file and you deleted X, it isn't surprising that problems arise.

  • Can we load data in variable screen from flat file?

    Hello all,
    One of my user once asked me she needs to run a report for some employees, i said you can just type that in employee varaible input box.
    She said I need to run the report and I need it for 120 employees, she has the employee numbers in excel sheet.
    What is the best way of doing this if any ?
    Thanks

    This can be done from a flat file, which has list of all values.
    If you are using Bex 3.5, then we have an icon in variable screen bottom right to upload values, where we can specify the path of the file.
    Naveen.a

  • Can Lightroom recognize and import gps coordinates from xmp files?

    Hello guys
    i have LR 4.2 and using Lion with a MBP.
    I recently got gps4cam for my iphone to record gps coordinates.
    Unfortunately i imported all the pix of my vacation to LR instead of importing them with the gp24cam app first
    so Now i have the xmp files with gps coordinates in a separate file for each photo, but LR even though ca see that file, does not import any of the info on it
    Is there a way to force LR to read and recognize those gps coordinates without having to delete all the pix of my vacation from LR, and re-import them to my mac before with the gps4cam app and afterwards import em in LR.?
    i mean i cant believe there is not way to do that...
    y LR can read and recognize gps coordinates if are on a picture, but cant recognize and attach those same coordinate to the original fine if they are in a separate xmp file?
    thanks for your input guys
    matteo

    I would process differently:
    Import your images as usual directly into LR, without the GPS data
    copy the gpx-track from your external device to a storage sport from where LR can access it (my choice: same folder as my images).
    Use either the map module to populate LR records with the GPS data (as stated by jim1403) or a plugin from Jeffrey Friedl for geo-encoding.
    If you want to have the GPS data in your xmp, trigger the save from LR then (cmd s; may be auto-activated in your catalog settings)
    Please note that several import problems have been reported by using other software before LR to update something. Do not let your GPS tracking software touch your images, especially if it offers to write into your proprietary raw files, at least not into your only copy of them... I consider this way too dangerous for my precious negatives. If it also creates xmp, then fine.
    I am also a happy user of MotionX-GPS.
    The real disdavantage of the LR command to read metadata from files is that it is all-or-nothing: it would be so convenient if one could choose which partial sort of metadata (EXIF, IPTC, development, GPS-coordinates, rating+caption+title) - but that would be a matter of a feature request, not for this forum.
    Cornelia

  • On an ipod touch 4th generation, how do I load and sync my music from the computer to the ipod without mixing up and/or losing all of my photos which I have in categories?

    On an ipod touch 4th generation, how can I load and sync my music from my computer to the ipod without losing and/or mixing up my photos which I have put into categories?

    Finally did somethign that fixed this.  I restored my hard drive.

  • Can we load and unload the files in the run time?

    Can we load and unload the files in the run time?
    For example there are four files named "test1.h & test1.c" and another set "test2.h & test2.c" (I attached them as attachment to this post).
    test1.h contains code:
    int variable; //variable declared as integer
    test1.c contains code:
    variable = 1; //variable assigned a value
    test1.h contains code:
    char *variable; //variable declared as string
    test1.c contains code:
    variable = "EXAMPLE"; //variable assigned a string
    So here, in this case can I dynamically load / unload the first & second group of files so that the same variable name "variable" can be used both as integer and string? And if yes, how is that to be done?
    Solved!
    Go to Solution.
    Attachments:
    test.zip ‏1 KB

    What do you mean by "dynamically"?
    If you want to have a variable that either is an int or a char in the same program run, I'm afraid your only option is to define it as a variant and assign from time to time the proper data type in the variant according to some condition. Next, every time you access the variable you must firstly check which data type is stored in it, next access it in the proper way.
    If on the other hand your option or to have a run in which the variable is an int, next you stop the program and in a following run it is a char, you may have it by using some appropriade preprocessor clause:
    #ifdef  CHAR_TYPE
    #include "test1.h";        // variable defined as a char
    #else
    #include "test2.h";        // variable defined as int
    #endif
    Next, every time you want to access the variable you must proceed in the same vay:
    #ifdef  CHAR_TYPE
      variable = "string";
    #else
      variable = 1;
    #endif
    Does it worth the effort?
    Additionally, keep in mind that this "dynamical" approach can work only in the IDE, where you can properly #define your CHAR_TYPE or not depending on your wishes: when you compile the program, it will have only one #include depending on the definition of the macro.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Lightroom 6 is up and running.  Upgraded from LR5.  However I want to change the file name to be more generic, e.g., description in LR5 references LR5 and I want to change that to just John G's LR Catalog/Library.lrcat.  How can I accomplish this without

    Lightroom 6 is up and running.  Upgraded from LR5.  However I want to change the file name to be more generic, e.g., description in LR5 references LR5 and I want to change that to just John G's LR Catalog/Library.lrcat.  How can I accomplish this without fouling everything up?

    Ok, well you'll need to do something like this. Now this part is a little dependent on your database server:
           try {
                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
                Connection c = DriverManager.getConnection(
                                                           "jdbc:mysql://{database-server}/{database-name}:3306?user={username}&password={password}");
                Statement Stmt = c.createStatement();
                int count = Stmt.executeUpdate(cmd);
                if(count>0) {
                     System.out.println("count: " + count);
            } catch (Exception e) {
                e.printStackTrace();
        }That was some sample code for a MySQL database.
    Note that the applet can only contact the server that is was loaded from, so you might want to do a getCodeBase() or something like that to get the server address.
    Hope this is helpful.

Maybe you are looking for