OpenScript/How to add .jar file to Java Code in relative path

Hi all,
I want to add a .jar file which can be executed separately (like "java -jar A.jar") to my recorded Java Code.I've read this wiki http://everest2.us.oracle.com/wiki/Generic_JAR_Project about how to add a .jar file to "Assets", however, I cannot figure out how to use the .jarr file in Java code,I mean , how to get this .jar file like the method the databank added in "Assets"?
Things I did are as followed:
1.Execute my .jar file in OpenScript Java code with absolute path like this:
String cmd = "C:\Users\A.jar";
Runtime.getRuntime().exec(cmd);
This does work, but must set a absolute path in Java code like "C:\User\A.jar" ,which is not the workaround I want (I need my scripts can be run on other machines).
2.Try to get its current path with following codes:
File directory = new File(".");
String currentPath=directory.getCanonicalPath();
However,though this can get its absolute path (which is the the project path) in Eclipse like "C:\Users\Workspace\testProject", this only gets "C:\OracleATS\openScript" in OpenScript.
I thought to copy my .jar file to the project path , got its current path in java code first,then can know the path of .jar file, but this workaround failed because of the above reason.
I notice that in the "Assets" there are "Databanks","Object Libraries","JAR Files","Scripts". Since the databanks and scripts that added to "Databanks" and "Scripts" can be got or run in Java Code like:
*getDatabank("DatabankName").getNextDatabankRecord(); String data = eval("{{db.DatabankName.data}}");*
*or getScript("ScriptName").run();*
*Is there a method to get and run the jar file added to "Assets\JAR Files" like the above?*
Thank you very much!
Regards,
Angyoung

Hi DM,
Thanks for your reply!
I've found a workaround,which is calling OpenScript's APIs ,such as this.getScriptPackage().getRepository() and this.getScriptPackage().getWorkspace(),etc to locate the .jar file.
And this workaround can still work even though the script is run on other machine.
Sorry to reply you so late!
Regards,
Angyoung

Similar Messages

  • How to run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • How to add jar file in class path ?

    Hello,
    how can I add jar file in system class path.
    I am using Linux and installed java.
    Now I am creating one java package and working programs.
    I want to add commons-net-2.0.jar jar file into class path.
    how can I add in linux systems.
    Thank you.

    the same way you add anything else to the classpath.

  • How to add jar files to applet's classpath

    hi everyone,
    i got an issue to add jar file's to applt's classpath,
    i looked around accross many resources but getting no solution on this.
    i have a commons-httpclient3.1.jar and i have to make it available it to a an applet class bundled in a jar file say myjar.jar
    how can i achieve it?
    any help would be much appreciated
    thanks

    That's a long time I haven't written applets, but if I remind well, we are able to set multilple jar in the classapth parameter, separated by semicolon.
    Look the page http://java.sun.com/docs/books/tutorial/deployment/applet/html.html
    Edited by: jswim on Dec 6, 2007 3:51 PM

  • How to add .jar files in my project

    Hi all,
    i am designing a application where i want to translate some words of my web page to different language
    say, i want "search" word to be translated to french language
    i have got some .jar files google-api-translate-java-0.4.jar to do this work...
    can anyone tell in which folder to put .jar files ,so that it works in my project..
    i am using Eclipse SDK 3.3
    Thanks

    how to add .jar files in my project In your eclipse goto,
    Project --> Properties --> Java Buil Path --> Add External Jar
    By that u can select your JAR and click OK..........

  • How to add JAR files in JDeveloper 10.1.2

    Hi,
    We have developed a J2EE project using JDeveloper. Now, i have to add Upload CV functionality to the application. I want to use the classes provided by org.apache.commons.fileupload which is there in the commons-fileupload-1.2.2.jar file provided by them. My problem is i am unable to add this JAR file to my project. When i try to add this JAR file using the Project Properties of my project. Its asking me to browse the path of the J2SE Executable or EDIT the Class Path or Source Path or Doc Path. There is not option to add JAR files. If the JAR file is not added, its showing the errors:
    imported class 'org.apache.commons.fileupload.disk.DiskFileItemFactory' not found exception..
    Please let me know how i could associate JAR files to my project so that the upload files functionality is implemented. Will be desperately waiting for any assistance....
    Regards,
    Najmuddin

    Thanks John, that was helpful. After i added the JAR file, its showing me the following error:
    Error(479,16): class FileUploadException not found in class htdocs.recruitment._regMain.CommonsFileUploadServlet
    Is there any specific location where i need to keep my JAR file or i can browse it from anywhere?
    Regards,
    Najmuddin

  • How to add jar files which point to project

    when i create project in jse8 i added jar files form system.
    then when i move that project to another system it is asking for jar files.it is pointing to location from where we added.
    how to make jar files available locally so that i can move anywhere.

    This might be a CRUDE solution, but it helps :-)
    1. Create a new folder (e.g. lib) under your project
    2. Copy the interested Jars to the folder. ( I am not sure how to do from within the IDE, I just copied the jars using Explorer.
    3. Right-Click on the Libraries Node to add the Jars and Add them from the folder created in step 1.
    This works... :-)

  • How to add jar files to a project?

    What is the correct way to add jar files to a project?
    Jdev Help has an entry "Adding Files to a Project Using the Add Files or Directories Dialog", but when I goto File->Open as it says, there is no "Add Files or Directories" dialog.
    Using JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660 on Linux.

    That's not quite what I need, as it does not copy the files into the project, but just creates references to their original location in the filesystem. We want local copies so we can check the whole project into Subversion and not have external dependencies.
    Should I just copy the files manually (outside of Jdeveloper)? And what directory should I copy to?
    Thanks.

  • How to include .jar files in coldfusion code 

    To Integrate our cfm code with paypal jar files we do the
    following steps with our local coldfusion server ,and to run and
    integrate the paypal Java SDK jar files, I think we need to do the
    same process on the server, can you suggest any thing to do the
    following setting for my domain on the server, without setting the
    class path in coldfusion administrator.
    The ColdFusion application server must be configured to know
    the location of the PayPal JAR
    files, and your ColdFusion Markup (CFM) pages must be
    configured with the absolute path to
    the PayPal API certificate for the PayPal API user on whose
    behalf the calls are made.
    1. Install the PayPal Java SDK “Installing the
    SDK”.
    2. Copy a subset of the Java SDK JAR files to a location
    accessible by the ColdFusion
    application server. The JAR files are in SDK_root\lib and
    their exact names are as
    follows:
    – bcmail-jdk14-128.jar
    – bcprov-jdk14-128.jar
    – paypal_base.jar
    – paypal_stubs.jar
    sax2.jar
    – xerces.jar
    – xpp3-1.1.3.4d_b4_min.jar
    – xstream.jar-1.1.3.jar
    3. With the ColdFusion Application Server Administrator, add
    the absolute path of the
    location you determined in Step 2 to the Java and JVM
    CLASSPATH environment variable.
    4. Restart the ColdFusion Application Server.
    Suggest me how to include .jar files without setting
    classpath.

    > Suggest me how to include .jar files without setting
    classpath.
    Copy them to {CF_HOME}\lib, where {CF_HOME} is, for example,
    C:\CFusionMX7. Restart Coldfusion.

  • How to copy a file from Java code

    I have written a file through Java code in folder, say, "A". Now, I want a copy of that file exactly the same in some other folder "B". How, it can be done?

    http://java.sun.com/docs/books/tutorial/essential/io/streams.html

  • Running a jar file from java code

    Hi!
    Im trying to run a jar file from my code.
    I've tried Classloader, but that doesnt work because it doesnt find the images (also embedded in the 2nd jar file).
    WHat I would like to do is actually RUN the 2nd jar file from the first jar file. There must be a way to do this right?
    any ideas?

    ok, I found some wonderful code (see below) that will try to start the jar. But it doesn't. What it does is produce the following error when my application runs...
    So it's not finding the images in the jar file that I am trying to run? Strange. I checked the URL that sending, but it seems ok....
    I think I will check the url again to make sure......
    any ideas?
    Uncaught error fetching image:
    java.lang.NullPointerException
         at sun.awt.image.URLImageSource.getConnection(Unknown Source)
         at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
         at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
         at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
         at sun.awt.image.ImageFetcher.run(Unknown Source)
    the code....
    /* From http://java.sun.com/docs/books/tutorial/index.html */
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    import java.net.JarURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.jar.Attributes;
    * Runs a jar application from any url. Usage is 'java JarRunner url [args..]'
    * where url is the url of the jar file and args is optional arguments to be
    * passed to the application's main method.
    public class JarRunner {
      public static void main(String[] args) {
        URL url = null;
        try {
          url = new URL(args[0]);//"VideoTagger.jar");
        } catch (MalformedURLException e) {
          System.out.println("Invalid URL: ");
        // Create the class loader for the application jar file
        JarClassLoader cl = new JarClassLoader(url);
        // Get the application's main class name
        String name = null;
        try {
          name = cl.getMainClassName();
        } catch (IOException e) {
          System.err.println("I/O error while loading JAR file:");
          e.printStackTrace();
          System.exit(1);
        if (name == null) {
          fatal("Specified jar file does not contain a 'Main-Class'"
              + " manifest attribute");
        // Get arguments for the application
        String[] newArgs = new String[args.length - 1];
        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
        // Invoke application's main class
        try {
          cl.invokeClass(name, newArgs);
        } catch (ClassNotFoundException e) {
          fatal("Class not found: " + name);
        } catch (NoSuchMethodException e) {
          fatal("Class does not define a 'main' method: " + name);
        } catch (InvocationTargetException e) {
          e.getTargetException().printStackTrace();
          System.exit(1);
      private static void fatal(String s) {
        System.err.println(s);
        System.exit(1);
    * A class loader for loading jar files, both local and remote.
    class JarClassLoader extends URLClassLoader {
      private URL url;
       * Creates a new JarClassLoader for the specified url.
       * @param url
       *            the url of the jar file
      public JarClassLoader(URL url) {
        super(new URL[] { url });
        this.url = url;
       * Returns the name of the jar file main class, or null if no "Main-Class"
       * manifest attributes was defined.
      public String getMainClassName() throws IOException {
        URL u = new URL("jar", "", url + "!/");
        JarURLConnection uc = (JarURLConnection) u.openConnection();
        Attributes attr = uc.getMainAttributes();
        return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
       * Invokes the application in this jar file given the name of the main class
       * and an array of arguments. The class must define a static method "main"
       * which takes an array of String arguemtns and is of return type "void".
       * @param name
       *            the name of the main class
       * @param args
       *            the arguments for the application
       * @exception ClassNotFoundException
       *                if the specified class could not be found
       * @exception NoSuchMethodException
       *                if the specified class does not contain a "main" method
       * @exception InvocationTargetException
       *                if the application raised an exception
      public void invokeClass(String name, String[] args)
          throws ClassNotFoundException, NoSuchMethodException,
          InvocationTargetException {
        Class c = loadClass(name);
        Method m = c.getMethod("main", new Class[] { args.getClass() });
        m.setAccessible(true);
        int mods = m.getModifiers();
        if (m.getReturnType() != void.class || !Modifier.isStatic(mods)
            || !Modifier.isPublic(mods)) {
          throw new NoSuchMethodException("main");
        try {
          m.invoke(null, new Object[] { args });
        } catch (IllegalAccessException e) {
          // This should not happen, as we have disabled access checks
    }

  • How to Add JAR files and Config files to CLASSPATH at runtime?

    QUERY:
    During runtime, I need to load the JAR files and relevant config files( .cfg files and .properties file) into CLASSPATH and run a specific java program from one of the JAR which is available in CLASSPATH.
    Please advise me any relevant Java API details or a sample java program to implement the above use case.
    Thanks in advance.

    During runtime, I need to load the JAR files and relevant config files( .cfg files and .properties file) into CLASSPATH and run a specific java program from one of the JAR which is available in CLASSPATH.
    Please advise me any relevant Java API details or a sample java program to implement the above use case.
    You don't add to YOUR classpath once your app is launched.
    You create a NEW process for the app you want to run and provide the proper environment for it to run in - including any PATH or CLASSPATH environment variables.
    The Java API for the ProcessBuilder class has a simple example that shows how to create the arguments and launch an external application.
    ProcessBuilder (Java Platform SE 7 )
    There are also PLENTY of other examples of using ProcessBuilder; just search the net.

  • How to add jar files in project?

    Hi everyone,
    Im stuck at one problem. I have third party API which are in jar files. I want to add reference those jar files in my projects. How to add all jar files at once in my project? Also, jar files are in different folders, like
    rootFolder
    {noformat} |- jar1.jar{noformat}
    |- jar2.jar
    |- Folder1
    | |-subjar.jar
    | |-subjar2.jar
    |- Folder2
    |- moreJars
    How to add all these jar files at once in my project? If u need more information, I will provide...
    Thanks in advance

    You can put the external references the in manifest of your own jar or you can do that at the bootstrap shell script.

  • How to add jar files?

    Hi all,
    I am using some external jar files for my backing bean.
    As of now I am adding jar files to my view properties in the libraries tab.
    when I shift my application to another machine I got to add the jar files again. Kindly comeup
    with the ways in which I can add the jar files permanently to my application. I dont want to add
    the jar files when ever I shift my app to other system.
    Thanks,
    Phani

    Do you use any kind of source control system (SVN, GIT, ...)
    That's the reason why you should. You normally put thirs party jars somewhere where you can access them from every pc.
    How do you 'shift your app' to an other machine?
    Just copy the directory? Then you can copy a directory containing the jars too.
    On other solution would be to put hte jars into the workspace folder of your app (e.g. tird-party-jars) and set up a library in dev pointing to this folder. Disadvantage of this method is that you need to do this for every app you create. So I wouldn't consider this as a solution.
    Timo

  • How to execute jar file in java project

    hi,
    i have made a proj in java in which i have put all my files in a jar file.
    can somebody help me how to execute this jar file??
    thanks

    u can put that jar file in ur class path,,
    regards
    shanu

Maybe you are looking for

  • My Apple ID is not being verified for FaceTIme

    I've changed my password twice and logged in successfully to apple id but when it tries to connect to FaceTime it says unable to verify email address then says it sent a verification link but it didn't and then says check network connection (which is

  • N86 support for free Navigation

    Hi I am thinking of ditching my Iphone and coming back to Nokia (because of the free navigation!). I really like the look of the N86 as it has all the features which are important to me. Can anyone tell me if it will support the free navigation softw

  • Smart form ..{Record should get the color}

    Hi, good day guys Thank you for supporting me. I got a prob in smart form. Ive dev the smart form and dev the custom programme for that form. my final itab got items with subtotal. Just iam passing the final itab to smart form. there iam using direct

  • Interested in Apple TV, have questions... :)

    Hello Apple folks, My wife and I are looking at either getting an Apple TV or a Bluray player, and wanted to know some things about the Apple TV. I've done some reading on the Apple.com website and saw that there are some compelling things about the

  • Problems after updating to firmware 3.0

    Hi all, On wednesday I had updated to version 3.0 for my iPod touch 2G. I could see comparing to other touch 2G (v 2.2.1) that WIFI connection is very slow into YouTube, Safari, AppStore and all apps that uses WIFI connection. When I look at Setup ->