Jar calling jar

what is the magic line that I have to add to my jar application in order to call another jar program ???
Regards Amnon

Do as #4 said to call main method directly ('main' of whatever class would be called from the jar).
Or, you'd have to use Runtime.getRuntime().exec(...), where the "..." is the same "java -jar ..." command you would run from the command line (note that there are several overloads of exec, depending on what you need--check the API).
And, read the standard advice for using Runtime.getRuntime().exec :
When Runtime.exec() won't:
Navigate yourself around pitfalls related to the Runtime.exec() method
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Similar Messages

  • Calling jar file from jsp - serious problem !

    Hi there, I'm trying to call a jar from a jsp file. I need an import clause in my jsp, to the class I want to use.
    I'm using eclipse, and while i"m writing "<%= " and the begining of my class name , he autocompletes it and automatically puts an import of my class in the top of the html. It is very convenient , but the problem is that he underling the class name (in the impot: <%@page import="myClass"%>), and I get "The import myClass cannot be resolved" error.
    I got an advice to put my class in a package, since it was in a default package. I did it. But now I have 2 problems:
    1. I can't run my jar in command window: java - jar myJar.jar. in gives me: Exception in thread "main" java.lang.NoClassDefFoundError....
    2. I still get an error - "The import myClass cannot be resolved" in the jsp, although I threw the old jar (that his class I want to use was out of package), and brought a new jar after creating it.
    I hope I managed to clarify myself. I'll be thankful of any help !!!

    Hi MSoldier.
    There are two ways to do this:
    1) You use the java.lang.Runtime classes to start the java application in your JAR file, just like you would have done it from the command line. The Runtime class has three different exec() methods that can be used to run any program just like you would from the command line. Remember, using this method you will have to write everything just like if you run your Java application from the command line, incl. classpath etc. This way your Java application will be run as a separate process. When the application finishes the process is shutdown and the resources (RAM etc.) taken by it freed, just like when you shutdown any other application.
    2) You can open the JAR file yourself from inside the JSP page, look inside the META-INF file to find the main class, and then calls the main class main method. There is an example of how to do this in the Java Tutorial available from Sun under the JAR files track. Check these links :
    The Java Tutorial at Sun
    http://java.sun.com/docs/books/tutorial/
    The JAR File Tutorial at Sun
    http://java.sun.com/docs/books/tutorial/jar/index.html
    Opening JAR Files via the Java JAR File API
    http://java.sun.com/docs/books/tutorial/jar/api/index.html
    Note however, if you have just created some classes that you want to use from inside your JSP pages, and not a separate application that needs to be run separately, you should just include the JAR file with your custom classes inside the WEB-INF/lib directory. These classes are then automatically available to your JSP pages, just like the rest of the Java API.
    I hope this answers your questions,
    Kind Regards,
    Jakob Jenkov
    Software Architect
    Jenkov Development
    www.jenkov.com

  • Call *.jar inside the trigger (MS SQL)

    Hi!
    I'm just looking around google and can't find any good news.. The problem is: how to call *.jar inside the trigger. Trigger is stored in M$ Server.
    Tnx, if any response! ;)

    What?

  • Calling jar -xvf

    Hi - I am trying to unjar a jar file by calling the jar command "jar -xvf". My code is calling the jar command but is not unjaring the jar file. This is my code:
    try{
    Runtime r = Runtime.getRuntime();
    Process p = r.exec("jar -xvf " + jardirectory + jarfile);
    }catch(Exception e){System.out.println(e);}
    Why is it not unjarring the Jar file? The only way I got it to unjar by calling a batch file that calls the jar command. I really want to unjar the file through Java, and not through a batch file. Thank you.
    Seigot

    see documentation for java.util.jar.* , esp. java.util.jar.JarFile

  • Call .jar in ANE for Android

    Hi everybody, can you tell us what is the way for this?:
    "We are building a new ane, that ane needs to call an external .jar"
    When we build Android apk works, however when we try to invoke inside of the .jar for the ane doesn't work.
    Let me make clear: ex.  ane->.jar->external .jar
    Thanks for your help.

    Hi,
    I think the problem here is actually something to do with the way AIR is packaging the assets. I've been investigating the issue trying to get access to video files packaged in an AIR app from an ANE but they are sometimes compressed in the APK rather than just being stored. Once they are compressed you get the error you've encountered:
    java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
    I think this has to be an error in the AIR packaging, as they shouldn't be compressed. Any files like mp3, mp4, png etc shouldn't be compressed according to the Android packager.

  • Java -jar -myApp.jar works but ....

    Hi there,
    I have a problem : using ant, I have exported my application into an executable jar file.
    When in the console, I type "java -jar myApp.jar" . Everything works well.
    But if, I do double click on the jar file, nothing happens. In fact, I can see a new Instance of javaw.exe in the "task manager" but nothing happens.
    It's kind of weird ...
    Has anybody an idea about that ??
    thanks in advance
    sylvain_2020

    I am having a similar problem.
    java -jar foo.jar works great, but double clicking seems to hang the app at a certain point.
    Unable to figure out what's going on, I've been putting some "JOptionPane.showMessageDialog()" calls to see how far it's getting. It appears to be hanging up when it tries to instantiate one of my classes that extends JPanel. I have a dialog appear right before calling the constructor (and I see that one), but I don't see the dialog that's in the constructor as the first executed line (so that it must hang up somewhere before that). I've also removed all constructors from the attribute declarations. That made me think it had something to do with the constructor of JPanel, over which I have no control.
    However, I can instantiate JPanel no problem.
    What the heck is going on???

  • Invoking jar through jar

    hi all,
    I have exported the "frames.java" file into a jar file called "frames.jar". I have also exported "invokejar.java" file into a jar file called "invokejars.jar".
    On doubleclicking invokejars.jar file, its not invoking frames.jar file. But when i execute invokejars.jar file through command prompt it works fine. Please help me to solve this problem.
    frames.java
    import java.awt.*;
    import javax.swing.*;
    public class frames extends JFrame
         public frames()
              super("Frames");
              setLayout(null);
              setSize(500,500);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              frames fr=new frames();
    invokejar.java
    import java.io.*;
    public class invokejars
    public static void main(String arg[])
    try
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("cmd.exe /C java -jar frames.jar");
    catch(Exception er)
                   System.out.println("Exception is :"+er);
    Thanks in advance
    Regards

    Is any part of the code firing? If not, double check your classpath. CLASSPATH should be set in the env file (default.env) and not the system environment. What you posted seems like it is missing some entries. Here is an example of the default CLASSPATH setting from an 11.1.1.4 installation.
    CLASSPATH=C:\Oracle\Middleware\as_1\forms\j2ee\frmsrv.jar;C:\Oracle\Middleware\as_1\jlib\ldapjclnt11.jar;C:\Oracle\Middleware\as_1\jlib\debugger.jar;C:\Oracle\Middleware\as_1\jlib\ewt3.jar;C:\Oracle\Middleware\as_1\jlib\share.jar;C:\Oracle\Middleware\as_1\jlib\utj.jar;C:\Oracle\Middleware\as_1\jlib\zrclient.jar;C:\Oracle\Middleware\as_1\reports\jlib\rwrun.jar;C:\Oracle\Middleware\as_1\forms\java\frmwebutil.jar;C:\Oracle\Middleware\as_1/jlib/start_dejvm.jar;C:\Oracle\Middleware\as_1\opmn\lib\optic.jarDepending on your environment, it may be necessary to also add the importer to the classpath: C:\Oracle\Middleware\as_1\jlib\importer.jar
    Given all that, why are you using a remote web service for a calculator rather than something like a java bean which will run locally? There is an example in the Forms demo set and likely many others on the web.
    http://www.oracle.com/technetwork/developer-tools/forms/downloads/index.html
    There is a calculator bean on a web site we often recommend, but be aware they appear to be having some site problems, so it may not be accessible.
    http://forms.pjc.bean.over-blog.com/article-35505095.html

  • Can't get matching xdb6.jar, xmlparserv2.jar and ojdbc6.jar

    No matter what I try, they are always somewhat different and I'm getting exceptions with JDBC on either setSQLXML or on .getString() once I retrieved the SQLXML object and want to get the content back or I'm downright getting "oracle.xdb.XMLType cannot be cast to java.sql.SQLXML"
    How is it possible that Oracle who owns Java and OracleDB can't make a working Java driver? I just want to be able to work with XML, I didn't know this was asking much. I have OracleXE installed.

    Welcome to the forum!
    Whenever you post you need to provide ALL of the product and version information applicable to the question or issue you are asking about
    >
    No matter what I try, they are always somewhat different and I'm getting exceptions with JDBC on either setSQLXML or on .getString() once I retrieved the SQLXML object and want to get the content back or I'm downright getting "oracle.xdb.XMLType cannot be cast to java.sql.SQLXML"
    >
    Before you submit a question or issue use the 'Preview' tab so you can see it as it will display. Then read your entire submission and ask yourself:
    >
    Could I answer a question like that based ONLY on the information that was provided?
    >
    For this thread the answer would be NO!
    All you have done is complain. That is basically the equivalent of a five year old saying 'Mommy, my tummy hurts'.
    >
    No matter what I try
    >
    What did you try? You haven't posted ANY information about what you are even doing, what jars, tools or code you are doing it with or HOW you are doing it.
    >
    I'm getting exceptions with JDBC on either setSQLXML or on .getString() once I retrieved the SQLXML object
    >
    What exceptions? You haven't posted ANY exceptions or any of the code that caused those exceptions.
    Retrieved WHAT SQLXML object? Retrieved from where? What is the full name and version of the database you are using? For Oracle that would be the 4 digit version as returned by 'SELECT * FROM V$VERSION'. Oracle DB doesn't have any SQLXML objects; it has XMLTYPE columns. Is that what you are trying to access?
    >
    Can't get matching xdb6.jar, xmlparserv2.jar and ojdbc6.jar
    >
    Where did you get them from? How did you get them? How do you know that they don't match? What is the full name and version of the jars that you are using?
    Have you used this functionality before? Do you know how to use it? If you have never used it and have no expertise with it we need to know that so we can tell you how to get up to speed so you can use it successfully.
    Since you haven't provided ANY of the information needed to provide any specific suggestions all we can do is assume that you are using the last, current version of Java and all jars files and have never used the functionality. In that case you need to start at the beginning.
    Review the relevant sections of the JDBC Developer's Guide
    http://docs.oracle.com/cd/E18283_01/java.112/e16548/jdbcvers.htm#BABGHBCC
    >
    SQLXML Type
    One of the most important updates in JDBC 4.0 standard is the support for the XML data type, defined by the SQL 2003 standard. Now JDBC offers a mapping interface to support the SQL/XML database data type, that is, java.sql.SQLXML. This new JDBC interface defines Java native bindings for XML, thus making handling of any database XML data easier and more efficient.
    The oracle.jdbc.getObjectReturnsXMLType Property
    In Oracle Database 10g and earlier versions of Oracle Database 11g, Oracle JDBC drivers supported the Oracle SQL XML type (XMLType) through an Oracle proprietary extension. XML values were represented by instances of the oracle.xdb.XMLType class and the SQL XMLType values were read and set through the JDBC standard getObject, setObject, and updateObject methods.
    The JDBC standard requires the getObject method to return an instance of java.sql.SQLXML type when called on a SQL XML type column. But, the earlier versions of Oracle JDBC drivers return an instance of oracle.xdb.XMLType. This does not conform to the JDBC standard.
    The current release of Oracle JDBC drivers conform to the JDBC standard with the introduction of a new connection property, oracle.jdbc.getObjectReturnsXMLType. If you set this property to false, then the getObject method returns an instance of java.sql.SQLXML type. You can achieve this by using the following command line option while compiling your program with javac:
    -Doracle.jdbc.getObjectReturnsXMLType="false"
    If you depend on the existing Oracle proprietary support for SQL XMLType using oracle.xdb.XMLType, then you can change the value of this property back to true by using the following command line option:
    -Doracle.jdbc.getObjectReturnsXMLType="true"
    The value of the oracle.jdbc.getObjectReturnsXMLType property is a String representing a boolean value of either true or false. If the value of this property is true, then the getObject method returns oracle.xdb.XMLType instances, when called for a SQL XMLType column. This is the deafault value of the oracle.jdbc.getObjectReturnsXMLType property. If the value of this property is false, then the getObject method returns java.sql.SQLXML instances. This is the standard JDBC-compliant mode.
    Note:
    The oracle.jdbc.getObjectReturnsXMLType property affects only the result of the getObject method. All other methods conform to the JDBC 4.0 standard regardless of the value of the property.
    >
    The exception that you are getting
    >
    oracle.xdb.XMLType cannot be cast to java.sql.SQLXML
    >
    is telling that the XMLType is NOT an SQLXML type so you can't use it as one. That doc section above should tell explain that those are two DIFFERENT types. You use one or the other depending on which version of the functionality you want to use. You can use the older 'non-JDBC' standard or the new 'JDBC' standard. But you can't mix the two.
    Review that entire chapter of the doc and see if that helps.
    If not then you need to provide ALL relevant information if you need more help:
    1. Java version
    2. DB name and version
    3. JAR file names and versions
    4. Java code that demonstrates the problem
    5. EXACT copies of any and all exceptions and errors that occur
    6. A description, in English, of what you are trying to do and how you are trying to do it.
    When you post use \ on the line before and on the line after any code to preserve formattting. See the FAQ for other formatting guidelines. Use the 'Preview' tab to see what your post will look like before you submit it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Error while using FJTable.jar & SwingButton.jar files in a same form

    Hi Experts,
    I am using forms 10.1.2 with Java Plug-in 1.6.0_02
    I have downloaded FJTable.jar & SwingButton.jar files from http://forms.pjc.bean.over-blog.com site. When I am using both files in one form, it shows error :
    java.lang.SecurityException: class "oracle.forms.fd.SwingButton"'s signer information does not match signer information of other classes in the same package”
    If anybody has any idea about this please help me
    Thanks
    Kalpesh

    Hello,
    You cannot run one form that contains more than one Beans that have not the same signature.
    Sign both the JAR files and everything is going to be OK ;D
    Francois

  • Adding a jar to the classpath of an executable jar (mixing -jar and -cp)

    Hello,
    frankly I hesitated over posting this to "New to Java"; my apologies (but also, eternal gratefulness) if there is an ultra-simple answer I have overlooked...
    I integrate a black-box app (I'm not supposed to have the source) that comes packaged as an executable jar (with a Manifest.MF that specifies the main class and a bunch of dependent jars), along with a few dependent jars and a startup script. Long story short, the application code supports adding jars in the classpath, but I can't find a painless way to add a jar in its "classpath".
    The app's "vendor" (another department of my customer company) has a slow turnaround on support requests, so while waiting for their suggestion as to how exactly to integrate custom jars, I'm trying to find a solution at the pure Java level.
    The startup script features a "just run the jar" launch line:
    java -jar startup.jarI tried tweaking this line to add a custom jar in the classpath
    java -cp mycustomclasses.jar -jar startup.jarBut that didn't seem to work ( NoClassDefFound at the point where the extension class is supposed to be loaded).
    I tried various combination of order, -cp/-classpath, using the CLASSPATH environment variable,... and eventually gave up and devised a manual launch line, which obviously worked:
    java -cp startup.jar;dependency1.jar;dependency2.jar;mycustomclasses.jar fully.qualified.name.of.StartupClassI resent this approach though, which not only makes me have to know the main class of the app, but also forces me to specify all the dependencies explicitly (the whole content of the Manifest's class-path entry).
    I'm surprised there isn't another approach: really, can't I mix -jar and -cp options?
    - [url http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html]This document (apparently a bible on the CLASSPATH), pointed out by a repited forum member recently, does not document the -jar option.
    - the [url http://download.oracle.com/javase/tutorial/deployment/jar/run.html]Java tutorial describes how to use the -jar option, but does not mention how it could play along with -cp
    Thanks in advance, and best regards,
    J.
    Edited by: jduprez on Dec 7, 2010 11:35 PM
    Ahem, the "Java application launcher" page bundled with the JDK doc (http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html) specifies that +When you use [the -jar] option, the JAR file is the source of all user classes, and other user class path settings are ignored+
    So this behavior is deliberate indeed... my chances diminish to find a way around other than specifying the full classpath and main class...

    I would have thought that the main-class attribute of the JAR you name in the -jar option is the one that is executed.Then I still have the burden of copying that from the initial startup.jar's manifest. Slightly less annoying than copying the whole Class-path entry, but it's an impediment to integrating it as a "black-box".
    The 'cascading' behavior is implicit in the specification
    I know at least one regular in addition to me that would issue some irony about putting those terms together :o)
    Anyway, thank you for confirming the original issue, and merci beaucoup for your handy "wrapper" trick.
    I'll revisit the post markers once I've actually tried it.
    Best regards,
    Jérôme

  • Error while running (java -jar orion.jar -install)  Need yr help ?

    Hi,
    I have
    Win 2000 Professional
    Oracle 9i release 1and have the Pre-Requisites of MapViewer as follows.
    OC4J_extended (Pre-Requisite for MapViewer)
    XML Parser (Built-in OC4J)
    Oracle 9iI don't know whether I have Oracle Client or not which is also pre-requisite for MapViewer ? I think it is built-in with any of the above... most probably with Oracle 9i !!!
    I have JDK1.3 as wellI have Oracle9iAS release 1.0.2.2.2a, but I don't want to use it, as I have OC4J standalone...
    I want to have the configuration, for using Oracle Spatial/MapViewer.... How can I do that ? I need steps/procedure...
    I am having problems in configuring OC4J which I have downloaded. I have unzipped OC4J_Extended in Oracle 9i Database home directory (not in Oracle 9iAS home directory... because I dont have installed iAS)
    Its installation guide asks for installation through the following command
    java -jar orion.jar -installbut after unzip, I don't get any file named "orion.jar"
    What should I do ? Where am wrong ? Should I have to use 9iAS for using MapViewer in any case, if so which version ? I need the heirarchy of steps ?
    I m really stucked !!!
    Any help would be highly appreciated.
    Thanx
    Zaaf.

    Hi,
    If you are just using OC4J, you should only need to do:
    java -jar oc4j.jar -install
    Also note that you should not install oc4j in the oracle_home
    directory. If/when you upgrade oracle to apply patches, etc
    it will overwrite/cause problems with your oc4j install if you
    put it in the oracle_home directory. Put it in any other directory.
    The only part of Oracle9iAS needed to run mapviewer is oc4j.
    After that is installed, then follow the instructions in the MapViewer
    User's Guide (available on OTN).

  • Getting error while running command java -jar oc4j.jar -install

    java -jar oc4j.jar -install
    ON RUNNING The above command getting below error , is it because Java home is not set?
    Warning: -jar not understood. Ignoring.
    Exception in thread "main" java.lang.NoClassDefFoundError: oc4j.jar
    at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
    at JvThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0)
    at JvRunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.5.0.0)
    at __gcj_personality_v0 (/oracle/u01/app/oracle/product/10.2.0/db_1/oc4j/j2ee/home/java.version=1.4.2)
    at __libc_start_main (/lib/tls/libc-2.3.4.so)
    at JvRegisterClasses (/oracle/u01/app/oracle/product/10.2.0/db_1/oc4j/j2ee/home/java.version=1.4.2)
    navisdb.igglobal.com(express)$ javac
    ksh: javac: not found
    ENVIORNMENT DETAIL : RED HAT LINUX ENTERPRISE EDITION
    Extracted OC4J_extended.zip file at oracle 10g installation location.

    does this command work?
    /home/oracle:MCSE>gij --showversion
    gij (GNU libgcj) version 3.4.6 20060404 (Red Hat 3.4.6-11)

  • Java -jar application.jar not finding file?

    I have an application program that contains the
    following two lines of code:
    FileInputStream sf = new FileInputStream "CustomWorld.ini");
    settings.load(sf);
    and when I run it as:
    java application
    it runs fine but if I run it as:
    java -jar -classpath .;application.jar application.jar
    it can't find the "CustomWorld.ini" file. Why is that
    and how can I fix it?
    Many thanks for your help.
    PS: to create the jar file I used:
    jar -cvfm application.jar application.mf application.class CustomWorld.ini

    Once your CustomWorld.ini file is in the jar, you can no longer access it directly with a FileReader. JDK 1.1 included resource locators to java.lang.Class...
    URL url = application.class.getResource("/CustomWorld.ini");
    if (url != null) { // resource was found
       InputStream in = url.openStream();
       settings.load(in);
    } else {
       // fail gracefully or use defaults
    }Note that the CustomWorld.ini file will need to be in the classpath or the root folder of the jar file for this to work.
    Regards,
    -Troy

  • Java -jar OrgFormatter.jar

    Hi All,
    I'm very new to Java. I'm trying to run this jar file and getting following error.
    java -jar OrgFormatter.jar VarshaTest060404.txt varshatest
    Failed to load Main-Class manifest attribute from OrgFormatter.jar
    OrgFormatter file takes two arguments <input file> and <output file>
    Please help me here.
    Thanks much
    Var

    if it doesn't work( the think is about the creating manifest file) you should study on the manifest files. I am wathching this topic

  • Java -jar Test.jar  option is not identifing the CLASSPATH on UNIX BOX

    Hi All,
    java -jar Test.jar
    I am trying to execute Test.jar file using -jar option. I am able to excute the Test.jar file but it is not identifing the CLASSPATH set for other JAR files which is used in part of Test.jar. Saying java.lang.NoClassDefFoundError: for the class which are set in CLASSPATH.
    The same is able to identify the CLASSPATH if i excute the Test.class file directly with out -jar option like
    java Test. In this case everything is working fine.
    Can any one tell me why it is not identifying the classpath if i use or execute with java -jar Test.jar option.
    Thanks,
    sha

    When you use the -jar option, the only classpath that is used is the Class-Path in the manifest file of the jar. If there is no Class-Path, then only the jar is searched for classes. If there is a Class-Path, the paths must be relative to the jar file.

Maybe you are looking for