Having JAR extract and execute a file

Not sure if this is the right board, but I am having trouble with this program. Basically I want the JAR file to extract the file included (test.exe) and then execute it on the system. After successfully getting it to work on my computer, I tested it on some of my others. However, the file would not even extract, let alone run. Is there something I am missing?
Here is the code:
try {
try {
JarFile jarFile = new JarFile("test.jar");
InputStream in = jarFile.getInputStream(jarFile.getEntry("test.exe"));
OutputStream out = new FileOutputStream("C:\\test.exe");
int c;
while ((c = in.read()) != -1) {
out.write(c);
in.close();
out.close();
jarFile.close();
} catch (IOException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
Process p = Runtime.getRuntime().exec("C:\\test.exe");
} catch (IOException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
}

The probable cause is that the input jar isn't being found. Try giving an absolute address for the jar.
By the way, nesting try/catch blocks isn't necessary and is unnecessarily complicated. This construct has the same effect.
try
    JarFile jarFile = new JarFile("test.jar");
    InputStream in =
        jarFile.getInputStream(jarFile.getEntry("test.exe"));
    OutputStream out = new FileOutputStream("C:\\test.exe");
    int c;
    while ((c = in.read()) != -1)
        out.write(c);
    in.close();
    out.close();
    jarFile.close();
    Process p = Runtime.getRuntime().exec("C:\\test.exe");
catch (IOException ex)
    Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
}

Similar Messages

  • WebDAV, php and executing the file

    I am having trouble with WebDAV executing PHP code when opening files remotely on the server using a text editor and not showing the php code.
    If we access the server through a text editing tool via WebDAV, it executes the php code and displays the resulting code in html, but not the original php code. But if we log-in to the server using FTP, same user, just different protocol, then the code is displayed as php code, but then that user then owns the file and we generate other permission problems.
    So the question is: How can you set up a machine to have users access the server only through WebDAV, but have the text editor they are using NOT execute the PHP files when they open, but show the php code?
    Many thanks for your help.
    Pilar

    Huh?
    And exe only runs on the machine that it is accessible from via the OS. So an exe on a server can 'run' on a client.
    There are word viewers that can be installed in a browser that allows a word file to be viewed in the browser. The viewer has to be installed in the browser however.

  • I download firefox 5.0 and now I'm having trouble dragging and dropping PDF files into Google Docs and I can't view the PDF once uploaded. I had no problems with this in the previous verion of Firefox

    With firefox 5.0 I can't drag and drop pdf files in the google docs screen. When I do eventually get a pdf file uploaded I can't view it. I get "no preview available". In my previous verion of firefox (4.something) I had no problems with this and I was able to drag and drop and after uploaded I could view the entire file.

    Thanks one again. I know you helped me the last to. I do have the Deja Vu font set in my folder. I downloaded and the last time. So I don't know if there is supposed to be more or not, but those were installed with Windows-XP after my reformat.
    This is really driving me nuts. as I've done several re-formats on my computer and several friends computers and even upgraded hardware so I am not necessarily a software or programming expert, I am somewhat advanced when it comes to computers in general and can usually diagnose the problem but these font's are the problem and they never were before.
    I did see in another forum that if you had a Dell Computer and did the Microsoft update for the onboard video card driver that it could be the culprit, but I have that disabled being I have a much better graphics card so the updates from Microsoft for the onboard video weren't installed.
    It' a Dell Dimension 3000 with an Intel(R) 82865G Graphics Controller so I don't believe it is the culprit being it is disabled. The actual video card that I am using is a PCI Nvidia GeForce 9400 GT with 1 GB Memory. And I didn't have any problem before.
    I appreciate the help. But still can't get things to work. Live Help Chat doesn't open for another two hours so maybe they can do "Remote Access" or something and can check setting and help me. But if you come up with other suggestions, they would be greatly appreciated.
    Thanks again.
    Susan

  • Jar Includes and executable .exe

    Hey guys,
    Here are a series of question I have for Jar files:
    1. How can I reference in source code a jpg/xml that was included in the jar file?
    2. How can I reference another jar file that was included in the jar file to do one of 2 things:
    _____1. Execute it
    _____2. Import it?
    3. Is it possible to include an exe file <for Windows Environment> and running it? eg: Abc.jar include def.exe <which really is a jar file converted to exe>; Now can i execute def.exe from a sourcefile thru Abc.jar using Run class?
    So tell me if these actions are possible and if they are how? If they are not, tell me so and possibly any work arounds you might know of.
    Thanks.

    To access resources from within your Jar you'll need to use methods on the class loader. Run a quick search on these forums (using: image jar) and you should find a few examples.
    I've been using the Fat Jar eclipse plugin (which uses One-Jar) to wrap up my code and supporting jars into a single jar resource.
    There is a thread (http://forum.java.sun.com/thread.jspa?threadID=588857&tstart=0) which will help if you use Fat/One-Jar.
    Sorry to be brief but like I say there a quite a few examples in this forum. Have a quick search. If you can't find what you need I'll check back later.
    Mark

  • How to compile and execute servlet file in j2ee

    In j2ee server when iam compiling servet i am getting error messages like package javax.servlet,and javax.servlet.http does not exist like that.
    i hsve set path like this.and i gave path for j2sdk .
    set CPATH=.;%J2EE_HOME%\lib\j2ee.jar
    javac -classpath %CPATH% AdderServlet.java
    can anybody tell me where to place
    servlet and how to compile it.
    Thank u,
    Renuga

    Make sure that '%J2EE_HOME%\lib\j2ee.jar' is existing. Where is your J2EE_HOME pointing to?
    The best thing I can suggest is, create your own bat file to compile the servlets. Like this,
    Save the lines below as "MyCompiler.bat" file.
    @echo off
    set JDK_HOME=<path to you jdk home upto bin directory>
    set J2EE_HOME=<path to you je22 home>
    set CLASSPATH=.;%J2EE_HOME%\lib\j2ee.jar
    %JDK_HOME%\javac %1
    Use the command,
    MyCompiler AdderServlet.java
    You can improve this MyCompiler.bat further, can add additional jar files to the classpath whenever you want. You can put this bat file in System's path, so that you can invoke it just by the name (MyCompiler) without giving the full path to it (like C:\mydir\MyCompiler).
    Hope this helps.
    Sudha

  • I am having problems donloading and editing .asx files

    I am trying to edit some video that can only be downloaded in .asx format. It is drm-ed. I may just have to contact the poeple I am partenring with that I need the original video files but I will need to do this with many of the cliebts that I am partnering with. Not only will it become a nuisance and make my business move as though stuck in the mud...it makes it hard for me to trumpet the relative merits of Apple anything electronic in the world if I have to get parralel or something so that I can run (gasp) Windows.
    Please help!
    If there is another section I should post this in let me know. i figured Fimal Cut would be where the most knowledgeable amble about.

    FCE is video editing application. ASX are not video files, they're metadata information. By the sound of it you haven't downloaded the video files at all. ASF is a Windows format used for streaming, not for download.
    The ASX Format
    ASX (Advanced Stream Redirector) files are not media files, but metafiles.
    Metafiles provides information about files. ASX files are plain text files used to describe multimedia content:
    <ASX VERSION="3.0">
    <Title>Holiday 2001</Title>
    <Entry>
    <ref href="holiday-1.avi"/>
    </Entry>
    <Entry>
    <ref href="holiday-2.avi"/>
    </Entry>
    <Entry>
    <ref href="holiday-2.avi"/>
    </Entry>
    </ASX>
    The file above describes three multimedia files. When the ASX file is read by a player, the player can play the files described.
    Advanced Systems Format (formerly Advanced Streaming Format) is Microsoft's proprietary digital audio/digital video container format, especially meant for streaming media. ASF is part of the Windows Media framework.
    The format does not specify how (i.e. with which codec) the video or audio should be encoded; it just specifies the structure of the video/audio stream. This is similar to the function performed by the QuickTime, AVI, or Ogg container formats. One of the objectives of ASF was to support playback from digital media servers, HTTP servers, and local storage devices such as hard disk drives.
    ASF is based on serialized objects which are essentially byte sequences identified by a GUID marker.
    The most common filetypes contained within an ASF file are Windows Media Audio (WMA) and Windows Media Video (WMV). Note that the file extension abbreviations are similar in name to the codecs of the same name but are different things.
    ASF files can also contain objects representing metadata, such as the artist, title, album and genre for an audio track, or the director of a video track, much like the ID3 tags of MP3 files.
    Files containing only WMA audio can be named using a .wma extension, and files of only audio and video content may have the extension .wmv. Both may use the .asf extension if desired.
    Certain error-correcting techniques related to ASF are patented in the United States (United States Patent 6,041,345 Levi, et al. March 21, 2000) by Microsoft. Although the format is publicly documented by Microsoft, its license limits implementations to closed-source development projects only. Apple's iTunes software (for Windows) now has the capability to convert WMA files to any iTunes-supported format.[1]
    The ASF container provides the framework for digital rights management in Windows Media Audio and Windows Media Video. An analysis of an older scheme used in WMA reveals that it is using a combination of elliptic curve cryptography key exchange, DES block cipher, a custom block cipher, RC4 stream cipher and the SHA-1 hashing function.
    ASF files have MIME type application/vnd.ms-asf or video/x-ms-asf. (Advanced Stream Redirector (ASX) files also have MIME type video/x-ms-asf.)
    ASF container-based media is usually streamed on the internet either through the MMS protocol or the RTSP protocol.

  • Differences between Debug .exe file and Execute .exe file

    We are very confused by the following problem when we are using
    LabWindows/CVI to develop our application:
    Our program is for retrieving data from real time and process the data to
    get the statistic results. If we run the program using "Run >> Debug
    OurProject.exe", it runs very well. However, if we run this same program
    in
    two steps: first using " Build >> Create Debugable Executable" menu, then
    using " Run >> Execute OurProject.exe", it can not run and outputs very
    different results. How come does this happen? What's the difference between
    these two kinds of running a program? Please help!

    it might be that there are some variables not initialized. the development environment automatically initializes all variables. an executable program does not.

  • Error message when trying to extract and install

    Why do I keep getting an error message for CS6 beta when I try to extract and install, message file missing?

    I assume you downloaded from here:  http://labs.adobe.com/technologies/photoshopcs6/
    Did you successfully download the file and check file sizes match? Do you extract ok?  PC, I assume? What OS are you using?
    How far did you get in the installation? Did you select TRY rather than enter serial number? Did you enter your Adobe ID?
    By the way, you should change your name to something other than your email as the bots will go nuts when they find that and you may get spam.
    Pattie

  • Java class to connect Windows server and excecuting bat file

    Hi All,
    Could some please provide or let me know how to connect windows server and executing bat file in windows box.
    All i have in hand to connect is Host name,Username and Password.
    Basically i am SOA guys and facing difficult in building class to do.
    I want to use Java code in my integration project in order to achieve the above case.
    I am using Linux OS. And i want to run Java code in Linux Box and to connect to Windows server
    Thanks in advanace
    Regards,
    Tarak.
    Edited by: Tarak on Aug 8, 2012 4:08 PM
    Edited by: Tarak on Aug 11, 2012 9:08 PM

    I'm afraid few if any of us are going to know anything more about connecting to Windows Server than you do. All I can suggest is to check if its client interface is publicly documented and try reverse engineering it from that.

  • Executing *.xml files as *.jsp files

    Under other web containers this usually takes about 4 lines in a config xml file.
    I am still hunting through the online doco
    but I was wondering if anyone could point
    me to the relevant section quicker ? ...
    Basically what I am looking to do is to
    tell the server to parse and execute *.xml
    files as *.jsp files. It should be a simple
    mapping somewhere in the config files.
    Thankyou in advance,
    Brian.

    Chuck,
    That isn't quite what I want to achieve. What I have done
    elsewhere is place the following servlet mapping in the Web
    Container's web.xml file.
    <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.xml</url-pattern>
    </servlet-mapping>
    which then causes all *.xml files to be processed as *.jsp files.
    Servlet name being the name of the servlet that processes the
    JSP files for the web container. Is there an equivalent
    thing under BEA ? Does BEA have a servlet which processes
    JSP files or does it use something different ?
    Cheers,
    Brian.
    "Chuck Nelson" <[email protected]> wrote:
    >
    Brian,
    You should be able to update the web.xml for this purpose
    e.g.
    <servlet>
    <servlet-name>myFoo</servlet-name>
    <jsp-file>SnoopServlet.xml</jsp-file>
    </servlet>
    See the following URL for a more detailed description
    http://edocs.bea.com/wls/docs61/webapp/components.html#100437
    Chuck Nelson
    DRE
    BEA Technical Support

  • 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){}
    }

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

  • Execute batch file having gmake command

    Hi,  I am executing batch file having gmake command in it, when i run batch file directly it works correctly,
    but when i try to execute it from LabVIEW using system Exec.vi  
    i got following error,  
    process_easy: DuplicateHandle(In) failed (e=6)
    process_easy() failed to launch process (e=6)  
    Thanks in advance

    What OS?
    How are you calling it in LV?
    What is in the batch file?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Download and execute jars without using javaws

    Hi
    I need to download and execute jars from remote computer. I hava jnlp file, but I strongly need to execute jars without using java web start.
    What is the best way to do this task?
    Thanks in advance :)
    Edited by: joekidd on Aug 3, 2009 5:55 AM

    joekidd wrote:
    The easiest the best:)The easiest way is to hire the programmers who made the Jar, to consult on your behalf to install the program, or advise on its installation. BTW - you said earlier.. "strongly need to execute jars without using java web start." Why? What advantage does that provide?
    So I download needed jars, add them to classpath and run my application (I get all information from jnlp file and pass them to vm and my application).
    But following exception occurs "Exception in thread "main" java.lang.NoClassDefFoundError: javax/jnlp/ServiceManager". What should I do?Get in contact with those programmers, because this app. is dependant(1) on functionality that is only available to web start apps.
    (1) Unless they put that call in there, just to ensure no one can run the app. outside web start. ;-)

  • Difference between .jar, .war and .ear file

    Hi,
    I am pretty new to J2EE technology.
    I would like to know what is the difference between .jar, .war and .ear files and how they are deployed on webserver.
    Thanks,

    Files with a .jar extension or JAR files, are essentially just a collection of files compressed using the ZIP/ZLIB compression format.
    JAR (short for Java Archive) files were introduced in the early days of Java as a means to conveniently package and distribute Java applications and components. Since then, a number of additions to the Java platform have followed suit. The introduction of the EAR file is one such addition.
    An EAR (Enterprise Archive) file is a JAR file that contains a J2EE application.
    A J2EE application is a group of Web modules that collectively perform as a single entity.
    A Web Module is an entity consisting of one or more resources such as HTML files, Java class files, XML files, etc. Web Modules are packaged in Web Archive (WAR) files.
    Looking at it from a top-down view, EAR files contain JAR files and WAR files. Packaging resources in WAR files, JAR files and eventually EAR files, makes it easy to reuse and reassemble components as new J2EE applications and distribute them to new environments.
    For example, Tomcat deals only with WAR files.
    So, in order to auto-deploy a Web application to a Tomcat environment, you must place an application's WAR file in the appropriate directory or use Tomcat's deployment tools to manually deploy the file.
    If you already have an EAR file that contains the WAR file, you can extract the WAR file and use it as is. If you do not have the EAR file or the WAR file, you can use any number of compliant tools to create the WAR file. Tomcat is a servlet/JSP container available from the jakarta.apache.org site.

Maybe you are looking for