Running an external app packed inside a jar

Hi!
I'm using these code that I found for executing an external application:
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("//home//guest//myNativeApp");
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.println("[INFO] Output of Runtime.exec() is:");
while ((line = br.readLine()) != null) {
System.out.println(line);
Now I'm trying to include "myNativeApp" inside the jar. So when I "call java -jar packedApp.jar" and
the external application should be executed. I know we can use this.getClass().getResourceAsStream("/myNativeApp") to have the path inside the jar file but
I couldn't spawn it. Any ideas? Thanks in advance.

Thank you for reply. I already checked that page. Actually I did not handle the errors in the example to keep the idea simple. I want to put my app inside the jar because later I will use its output and I need to distribute the jar with all the resources inside included the app. I know I will lost all my portability but is an specific need. Do you have a clue?

Similar Messages

  • How do i run a file that is inside a jar file?

    Hi all,
    Here's what I'm trying to do: on a Unix (Solaris) box, I have a shell script bundled in with my application in a jar file. All I want to do is run the shell script from inside my java app, but I'm having trouble doing so.
    If i try the following code:
    Process process = Runtime.getRuntime().exec("myproject/tools/scripts/myscript.sh");
    int exitVal = process.waitFor();I get the following error:
    java.io.IOException: myproject/tools/scripts/myscripts.sh: not found
            at java.lang.UNIXProcess.forkAndExec(Native Method)
            at java.lang.UNIXProcess.<init>(UNIXProcess.java:52)
            at java.lang.Runtime.execInternal(Native Method)So then I did some searching and tried something like :
         ClassLoader cl = this.getClass().getClassLoader();
         URL the_file = cl.getResource("myproject/tools/scripts/myscript.sh");
         Process process = Runtime.getRuntime().exec(the_file);
         int exitVal = process.waitFor();but i get this error:
    cannot resolve symbol
    symbol  : method exec (java.net.URL)
    location: class java.lang.Runtime
         Process process = Runtime.getRuntime().exec(the_file);So is that the right way i should be doing this? Should i convert the URL (the_file)
    to something else before passing to exec()?
    Any hints/help/suggestions would be greatly appreciated.
    Thanks.

    The trouble with your first attempt might be that your relative path to the shell script is not relative to where you think it is. You could try again with an absolute path to the script as a simple test. Assuming that works you can try a more permanent solution -- perhaps a startup script for the Java app that defines a base path or a Properties file.
    You are exactly right about the problem with your second try. The exec method in all its forms expects a String as the first argument, so the URL is not going to help much, assuming that the URL is in fact non-null.

  • How to capture keyboard strokes while focus is on an external app. Opened with system exec

    Hi to the Forum,
    I have an application that runs an external app. Through system exec, while this application is open the user needs to input a 6 digit serial number using the keyboard, I need to capture in parallel that information on my main VI in order to perform some information validations, such as the six digits were entered, the serial number is not repeated etc. I have read other post about the same issue but did not found a practical way to achieve a solution, please help with an example of how to do that as I'm on the final stage of the project.
    Thanks in advance for your time and help.
    MRDK

    Hi MRDK,
    You can/have to use Connectivity>>Input Device Control palette functions.
    Attached is the simple example.
    Regards,
    Yogesh Redemptor
    Regards,
    Yogesh Redemptor
    Attachments:
    Get Keyboard Event.vi ‏15 KB

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

  • Getting External Apps to show up inside the Portal

    Hello,
    I am able to login a user in an external
    app. Is there a way that the app opens up
    in the same window(inside the portal would be even better) as the Portal ? Currently, it
    pops up in a new window. Can I change the code which builds the external apps list (wishful thinking here)
    Sanjay

    Sanjay,
    We will have the ability to display the first screen of external applications in a future release.
    Rich
    This thread has been moved from the Oracle9iAS Portal Forum to the Orac le9iAS Portal Security and Login Server forum. It is unlocked in the Oracle9iAS Portal Security and Login Server forum and responses should be posted there.
    Thanks,
    Rich

  • Using resources from an external JAR inside a JAR

    Hi,
    I'm trying to package all parts of my application into a JAR file so I can deploy my application using Java Web Start. However, I have an issue.
    I need to use the files from an external JAR, Ice.jar, with my application. Therefore, I included Ice.jar in my build, specifically in the lib/Ice.jar directory.
    This does not seem to be working; my application cannot read the information from the Ice.jar file when I launch my JAR file. It does work in one instance, however:
    I have a directory included in the same directory where my JAR file is. This directory is named lib, and contains Ice.jar. My directory structure is as follows:
    dist
    dist/NVAC.jar //my JAR
    dist/lib/Ice.jar //the external JARMy JAR file, NVAC.jar, will ONLY work if that lib directory is included in its directory. This is NOT what I want to do; I want to include the external JAR inside my JAR file, so a user will only have to download the JAR file. I have included the external JAR inside my JAR as I mentioned previously; at the path myJAR/lib/Ice.jar.
    Therefore, how do I use a resource from an external JAR inside my JAR? Do I have to use ClassLoader? ClassLoader.loadClass() perhaps?
    If I can provide any more information, please let me know.
    Thanks

    Seems to me it isn't practical to want to do things
    that don't work. Especially since you're using
    WebStart and it takes care of dependent jars
    automatically for you if you configure things
    correctly, so this absurd idea of jars inside jars
    isn't even helpful.Dang DrClap, you seem to be the go-to guy for destroying all my ridiculous ideas (no offense; I mean that in a good way).
    Seems I did not understand JWS fully when I thought of that idea. I researched it more after reading the replies here, and I see that I was indeed thinking absurdly.
    Thank you for the help,
    Dan

  • Running External Apps

    Is there a method that will run an external application?
    Thanks!
    dwl

    Are you refering to having Java run a non java application or are you refering to running another application on a different computer and getting something back from it. The later uses RMI (Remote Method Invocation) and there is a whole help section on that.
    http://developer.java.sun.com/developer/onlineTraining/rmi/index.html

  • 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

  • Running scripts, bat files, etc from a jar file

    Hello,
    Does anyone know of a way, or even if it is possible to run a script or batch file from a jar file?
    For instance, lets say I have a batch file that I can run from the command prompt by typing :
    myBatchFile.bat
    and now I write a very simple java app that will do the same:
    public class Test {
    public static void main(String[] args) {
    try {
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(�myBatchFile.bat�);
    } catch (Exception e) {
    e.getMessage();
    The above app will work as long as the batch file is in the current directory, but how or can I make it work if I stick the batch file in a jar file along with the app?
    I tried using the manifest file with no luck.
    I tried creating a URI to the jar file, wrapping it in a File and then passing that File to the exec method also with no luck.
    I searched all the forums on Sun but came up with nothing.
    I performed a google search also with no luck.
    Does anyone have the answer to this? Even if I can get a definitive �No it can�t be done� answer. Although I would think that it should be able to be done.
    Thanks

    Hi,
    you cannot execute anything being inside a jar-file. The OS doesn't know anythig about jar-files and cannot look inside one to find the program/script/batch you want to execute.
    You could do a workaround by extracting the file from the jar-file before calling exec(). But normally OS dependent files should not be inside a jar-file and remain in a own directiory.
    Andre

  • AIR app communnicating with External App

    I would like to make my AIR app communicate with another
    application that's running on the desktop. What are the best ways
    to do this?
    Ideally I'm looking to call functions inside the AIR app from
    a separate program, and vice versa. This is in fact possible using
    the ExternalInterface capability, however, this is only available
    when the separate application is an ActiveX container (such as the
    browser), and thus contains the FlashPlayer ActiveX control within
    it. But what if your AS3 application doesn't just run inside the
    FlashPlayer but requires the AIR runtime instead? There doesn't
    seem to be any way that an external app. can talk to an AIR app the
    way it can call functions on the FlashPlayer.
    My reasons for needing this are that while AS3 is great,
    especially for creating an interactive interface, there are still
    some low-level things which must be coded in another language.
    Any thoughts that anyone has on this topic would be greatly
    appreciated.

    Hi Bruce,
    In theory, you can do what you want, but it is an indirect
    way of achieving it, and there are some performance/functional
    issues.
    You can make a windows application that is an ActiveX control
    container, and put the FlashPlayer control inside it. Handle the
    "FlashCall" event in your windows program (this is fired when your
    swf calls a custom external function), and then you can use it to
    load and call whatever .dll function you want.
    In practice, from what I've observed, there are some
    limitations. The graphics performance of the FlashPlayer suffers
    when embedded this way in a Windows app. Also, if you want to call
    into the flashplayer sometimes the function calls fail. Having said
    this, my experience is limited to AS2 implementations; maybe things
    have improved with AS3.
    Anyway, hope this helps. Would be interested to hear your
    observations if you should try this route.
    Ed

  • How to pack .class or .jar with jvm into an exe file?

    In fact, .class or .jar files are middle layer files who need JVM to explain and run them. Sometimes it's unconvenient. Why not provide some tools to pack .class or .jar with jvm into exe file?

    because java should be able to run on any OS. That is why SUN doesn't provide such tool. There are other company's who does provide such tool. Like JBuilder enterprise

  • 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 to execute a java script from an external app

    Just new to Acrobat SDK,
    Given that I've started Acrobat from external app,
    I can get a JSObject, but how do I get ito execute a script
    e.g., found this in doco
         var pp = this.getPrintParams();
         pp.interactive = pp.constants.interactionLevel.automatic;
         pp.printerName = "Our office printer";
         this.print(pp);

    I was able to get it to work by coding directly in VB, but can you expand on the 2nd part, "pass it as a string to run"
    So, in VB I have
              jsObj = pdDoc.GetJSObject
    I tried
         jsObj = "var pp = this.getPrintParams(); ... "
    but that doesn't seem to do anything

  • 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

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

Maybe you are looking for