Using a jar file in my application... how?

I have a JAR file which contains some classes I need to use in my application. I however, after looking in several books, cannot figure out how to use this JAR file within my application.
Do I simply put it in the directory with my .java files, and use an import command? I'm confused.

If the classes in the jar are part of a package then you can import them based on the package structure. The jar file will have to be part of your CLASSPATH variable.
i.e.
myUtils.jar
resides in C:\"My Classes"
CLASSPATH = .;"C:\My Classes";"C:\My Classes\myUtils.jar"
within the jar I have the following class:
\ameyer\Util\someUtil.class
\ameyer\Util\anotherUtil.class
To use these classes I could use the following import statement
import ameyer.Util.*;
This would import any class at that level in the jar.
Note: the import part of the CLASSPATH is "C:\My Classes\myUtils.jar"
hope this helps.

Similar Messages

  • Problem using misc jar-Files in Composite Application

    Hi there,
    I want to use different jar-Files in my Composite Application on SAP Netweaver 7.3.
    I have created an external Lib DC where I have inserted the libs. After that I created an enterprise EAR and added the dependency to the PP of the external lib DC.
    After that I added the a dependency to my CAF-EAR. But I cannot access the mehtods and functions from my jar files.
    What's wrong there?
    Another question: Is it possible to add the jar-files directly to my CAF-EAR without creating the external library DC and adding a dependency?
    Any help would be greatly appreciated
    Thanks

    Hi, I've downloaded Jacob and got it running on my installation by doing the following:
    1. Download http://danadler.com/jacob/jacobBin_17.zip.
    2. Extract to Jdeveloper10g/jdev/lib/ext/Jacob
    3. Copy jacob.dll to c:/windows/system32
    4. Add JDeveloper10g/jdev/lib/ext/Jacob/jacob.jar to JDev user libraries, calling it 'Jacob'
    5. Add the 'Jacob' library to the project.
    6. Create a word document at c:/java/jacob/file_in.doc
    7. Create a new class with the following code:
    package view;
    import com.jacob.*;
    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.Dispatch;
    import com.jacob.com.Variant;
    public class TestJacob
    public TestJacob()
    * @param args
    public static void main(String[] args)
    TestJacob testJacob = new TestJacob();
    testJacob.runTest();
    public void runTest()
    boolean tVisible = true;
    String sDir = "c:\\java\\jacob\\";
    String sInputDoc = sDir + "file_in.doc";
    ActiveXComponent oWord = new ActiveXComponent("Word.Application");
    oWord.setProperty("Visible",new Variant(tVisible));
    Object oDocuments = oWord.getProperty("Documents").toDispatch();
    Object oDocument = Dispatch.call(oDocuments, "Open", sInputDoc).toDispatch();
    }

  • How to use a jar-file in an Application Service - NWDS 7.01

    Hello everybody,
    I want to create an Application Service in SAP NetWeaver Developer Studio 7.01.05. Can you explain me how i can import an external jar into my project?
    I found out that I can implement or create simple java files:
    Java Perspective --> package project_name.utils --> insert/create java file
    I try to add the jar into the java build path of my project, but when i build it the jar is gone.
    I would be very thankful for every hint.

    solved
    [http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/60d99678-1a29-2d10-94b4-9d9a67b7199b]

  • Using JAR file in running application and POI !

    Hi all
    I am trying to use POI HSSF f(for the first time, So pls bear with me!)or creating excel file from my java Application. I am using the jar file :
    poi-2.0-RC2-20040102.jar. Not sure if its the correct one. So If I am wrong pls correct me.
    Now I am creating a bat file to compile my application:
    @echo off
    C:\jdk1.3.1_04\bin\javac -classpath C:\POI\poi-2.0-RC2-20040102.jar MyApp.java
    pauseIt compiles fine. Now If I try to use the jar file in run.bat for running my application, it says NoClassDef FoundError:MyApp. Here is my run.bat
    java -classpath C:\POI\poi-2.0-RC2-20040102.jar MyApp
    pauseI am not able to run my application with this run.bat file . If I change the content to:
    "java MyApp.java"
    It runs but give me error: NOClassDefFoundError:import org.apache.poi.hssf.usermodel.HSSFWorkbook
    Pls suggest me about how to use jar file in running my app and how to rresolve workbook finding problem.
    Reagrds

    Try this:
    java -classpath .;C:\POI\poi-2.0-RC2-20040102.jar MyApp
    pauseNote the "dot semi-colon" at the start of the CLASSPATH. That puts the current directory in the CLASSPATH, which is where MyApp.class lives. (No package, right?)
    See if that works better.

  • How do we use our .jar file of Re-Usable Business Components in 11g?

    Hi All:
    We have developed a library of re-usable Business Components in 10g utilizing the instructions found here:
    http://download-west.oracle.com/docs/cd/B31017_01/web.1013/b25947/bcadvgen007.htm
    We are now planning on migrating to 11g, so we need to know how to implement this re-usable business component library.
    Is it possible to use it as it stands created in 10.1.3.3?
    Or do we have to migrate it over? And how is this done since we still have applications that use it in 10g?
    Your input is very appreciated since this is an important step in our migration plan. Doing this correctly is crucial to our shop. We have been trying a few things, so far with no luck.
    Thanks very muich.
    Mary
    UofW

    Shay:
    My colleague that received the errors is going to unexpectedly be off for a few days, so I tried to re-create the errors so that I could get back to you. What was essentially happening was that on certain tables, the first column was missing from the EntityImpl. These tables MIGHT be those that had a primary key that when JDev removed the underscore, had the same name as the Oracle table. For example the table name was ResidenceCode and the primary key of that table was Resident_Code and was found as the first column in the table. HOWEVER, when I tried migrating our reusable business components libarary .jar file, using 11.1.1.2.0, I did not experience the same errors, so I'll get back to you. She was perhaps using an older version of 11g?
    But I do have one question. Can we use a .jar file of reusable business components built in 10g in 11g? As you can imagine, this library is being used in other applications, and we'd like to prevent having two copies, if at all possible. Because of all the structural changes, I am guessing we can't, but I'd really appreciate your reply.
    I have found the documentation *36.7 Working with Libraries of Reusable Business Components* at http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/bcadvgen.htm#CHEFECGD with respect to 11g. If you know of any other 11g considerations with respect to this task, that would be great as well.
    Thanks Shay, I really appreciate hearing from you.
    Mary
    UofW

  • Gridworld Case Study - how to use a .jar file with textpad

    Hello,
    I am a student currently working on a project involving the Gridworld case study. While trying to work on my project at home, I discovered that I would get new "cannot find symbol" compiler errors that I had not previously gotten while compiling the same code at school. I am assuming this has something to do with the .jar file included in the gridworld code. How do I get textpad and/or the java compiler to find and use the .jar file and reccognise the classes which i am importing and extending in my project?
    Thanks,
    -Alex

    Thanks, It works for compiler now.
    Now, I write a html to run the applet. appletviewer
    says "
    java.lang.NoClassDefFoundError: ij/process/ImageProcessor
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
    at java.lang.Class.getConstructor0(Class.java:1762)
    at java.lang.Class.newInstance0(Class.java:276)
    at java.lang.Class.newInstance(Class.java:259)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:566)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:495)
    at sun.applet.AppletPanel.run(AppletPanel.java:292)
    at java.lang.Thread.run(Thread.java:536)
    It seems the appletviewer can not find the right path for the package. How can I fix this?
    Thank again,
    Hillxy

  • Using a JAR file as a project file

    My application allows the user to create projects. Previously, a project file was simply an XML file. Now, a project file needs to also contain many images.
    I thought it would be a good idea to simply use a JAR file as my project file.
    Since I've really never really worked with JAR files and the java.util.Jar package directly, I have a few questions.
    1) Would it be better just to simply store the images as binary in the XML file? I just spent a good amount of time making the XML file very readable so I thought it would be better to keep the images separate while still having a single "project" file.
    2) Is there anything inherently wrong with the way I'm working with the JAR file in the code below?
    Simple XML file:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE project [
      <!ELEMENT project (img+)>
      <!ELEMENT img EMPTY>
      <!ATTLIST img src CDATA #REQUIRED>
    ]>
    <project>
         <img src="blah.jpg"/>
    </project>
    import java.io.*;
    import java.util.jar.JarFile;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    public class LoaderTest {
        private String imageName;
        public LoaderTest() {
            InputStream i = null;
            JarFile jf = null;
            try {
                jf = new JarFile("project.jar");
                i = jf.getInputStream(jf.getJarEntry("project.xml"));
                // Here's my simple XML parser to load the project and images
                SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
                parser.parse(new InputSource(i), new DefaultHandler() {
                    @Override
                    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                        // Right now we only care about images
                        if (qName.equalsIgnoreCase("img")) {
                            imageName = attributes.getValue("src");
                // Load the image from the inputstream
                java.awt.image.BufferedImage img = javax.imageio.ImageIO.read(jf.getInputStream(jf.getJarEntry(imageName)));
                // Display the image in a JFrame
                javax.swing.JFrame f = new javax.swing.JFrame();
                f.setLayout(new java.awt.BorderLayout());
                f.setSize(800, 600);
                f.getContentPane().add(new javax.swing.JLabel(new javax.swing.ImageIcon(img)), java.awt.BorderLayout.CENTER);
                f.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
                f.setVisible(true);
            } catch (ParserConfigurationException ex) {
                ex.printStackTrace();
            } catch (SAXException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                // Do our best to close the input streams
                if (i != null) {
                    try {
                        i.close();
                    } catch (IOException ex) {}
                if (jf != null) {
                    try {
                        jf.close();
                    } catch (IOException ex) {}
        public static void main(String[] args) {
            new LoaderTest();
    }Thank you!

    1) I also think it's much better to keep your images separate from your XML, this prevents a lot of in case you just want to read XML data
    2) What's exactly going wrong here? For the project.xml, make sure it's not inside a directory within the JAR file, or else the variable i will be null. Otherwise it looks fine..

  • Use of Lookup Files in BI Applications

    Hi,
    Can any one tell the use of lookup files in BI Applications. While doing the configurations (for all modules) for these lookup files we get the data from the ERP database tables using the query provided by oracle and populate the file and then map with some domain values.
    Why cant we directly populate the datawarehouse tables using the ERP tables instead of populating through the lookup files (which we any how populate with ERP tables). Also what is the use of domain values. Does these use in reporting puposes and anlyzing the data or business.
    Thank You,

    For e.g, when you map the GL group account numbers, the predefined group codes such as 'CASH', 'AR', 'AP' , 'TAX' etc are the domain values. In the repository, the metrics are defined based on these domain values.
    Say, you mapped your CASH accounts from 0011 through 0100, then OBIEE calculates the metrics related to CASH as summation (or some kind of calculation) on the accounts that have the group codes (domain values) as CASH.
    It should be possible to update the domain values directly from ERP database tables but the ETL expects the mapping to be in files. Also in some cases we cannot change the default domain values, all we can change is the mapping to these domain values or create new domain values. At one client, we had to create a new account group code called 'FIXED ASSET' as the default domain values were not sufficient but then we had to change the repository to include new metrics and change existing ones to incorporate this new group code.
    -Nilesh
    http://www.appsbi.com

  • Problem with using external jar file

    Hi
    I was using mail.jar library for swing application to send and receive emails. It just works perfect when I run with netbeans. But when I run the executable jar file at dist folder it runs but mail related functions doesn't work.What should I do now to make it work with mail features outside netbeans.
    thanks
    vinay
    Edited by: 899657 on Dec 24, 2011 5:07 AM

    899657 wrote:
    No. Because I am running the jar file which is created by netbeansNetbeans creates a 'dist' directory in which it puts your jar and a "dist/lib' directory in which it puts the dependent jars that are added to the project using 'project right mouse click'->Properties->Libraries. I would expect to see this 'dist/lib' directory contain mail.jar and activation.jar and any other jars that your jar needs. Within your program jar's manifest I would expect to see the Class-Path attribute have relative reference these jars ( lib/mail.jar lib/activation.jar ) and for the Main-Class attribute define your main class.
    Given this setup then you should be able to just type -
    java -jar yourjar.jarto run your program.

  • HT1766 I have an iphone 4.I upgraded it to 5.0.1 and so I have lost all the data from my iPhone,but i have a backup in my computer.How do I use the backup file ? i.e How will i get that backup file in my iPhone ?

    I have an iphone 4.I upgraded it to 5.0.1 and so I have lost all the data from my iPhone,but i have a backup in my computer.How do I use the backup file ? i.e How will i get that backup file in my iPhone ?

    Connect phone to computer.
    Select Restore.
    Tell iTunes which of the available backup files to use, let iTunes restore it.
    Also, try reading the User's Guide as it answers questions like this.

  • How to create and use library JAR files with command-line tools?

    Development Tools -> General Questions:
    I am trying to figure out how to put utility classes into JAR files and then compile and run applications against those JAR files using the command-line javac, jar, and java tools. I am using jdk1.7.0_17 on Debian GNU/Linux 6.0.7.
    I have posted a simple example with one utility class, one console application class, and a Makefile:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130520-2134.tar.gz
    Here is a console session:
    2013-05-20 21:39:01 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-20 21:39:12 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/hello/HelloConsole.java
    package com.example.hello;
    import static com.example.util.Hello.hello;
    public class HelloConsole {
        public static void main(String [] args) {
         hello("world!");
    2013-05-20 21:39:21 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -f hello
    find . -name '*.class' -delete
    javac src/com/example/util/Hello.java
    javac -cp src src/com/example/hello/HelloConsole.java
    echo "java -cp src com.example.hello.HelloConsole" > hello
    chmod +x hello
    2013-05-20 21:39:28 dpchrist@desktop ~/sandbox/java/jar
    $ ./hello
    hello, world!I believe I am looking for:
    1. Command-line invocation of "jar" to put the utility class bytecode file (Hello.class) into a JAR?
    2. Command-line invocation of "javac" to compile the application (HelloConsole.java) against the JAR file?
    3. Command-line invocation of "java" to run the application (HelloConsole.class) against the JAR file?
    I already know how t compile the utility class file.
    Any suggestions?
    TIA,
    David

    I finally figured it out:
    1. All name spaces must match -- identifiers, packages, file system, JAR contents, etc..
    2. Tools must be invoked from specific working directories with specific option arguments, all according to the project name space.
    My key discovery was that if the code says
    import com.example.util.Hello;then the JAR must contain
    com/example/util/Hello.classand I must invoke the compiler and interpreter with an -classpath argument that is the full path to the JAR file
    -classpath ext/com/example/util.jarThe code is here:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130525-1301.tar.gz
    Here is a console session that demonstrates building and running the code two ways:
    1. Compiling the utility class into bytecode, compiling the application class against the utility bytecode, and running the application bytecode against the utility bytecode.
    2. Putting the (previously compiled) utility bytecode into a JAR and running the application bytecode against the JAR. (Note that recompiling the application against the JAR was unnecessary.)
    (If you don't know Make, understand that the working directory is reset to the initial working directory prior to each and every command issued by Make):
    2013-05-25 14:02:47 dpchrist@desktop ~/sandbox/java/jar
    $ cat apps/com/example/hello/Console.java
    package com.example.hello;
    import com.example.util.Hello;
    public class Console {
        public static void main(String [] args) {
         Hello.hello("world!");
    2013-05-25 14:02:55 dpchrist@desktop ~/sandbox/java/jar
    $ cat libs/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-25 14:03:03 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -rf bin ext obj
    mkdir obj
    cd libs; javac -d ../obj com/example/util/Hello.java
    mkdir bin
    cd apps; javac -d ../bin -cp ../obj com/example/hello/Console.java
    cd bin; java -cp .:../obj com.example.hello.Console
    hello, world!
    mkdir -p ext/com/example
    cd obj; jar cvf ../ext/com/example/util.jar com/example/util/Hello.class
    added manifest
    adding: com/example/util/Hello.class(in = 566) (out= 357)(deflated 36%)
    cd bin; java -cp .:../ext/com/example/util.jar com.example.hello.Console
    hello, world!
    2013-05-25 14:03:11 dpchrist@desktop ~/sandbox/java/jar
    $ tree -I CVS .
    |-- Makefile
    |-- apps
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.java
    |-- bin
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.class
    |-- ext
    |   `-- com
    |       `-- example
    |           `-- util.jar
    |-- libs
    |   `-- com
    |       `-- example
    |           `-- util
    |               `-- Hello.java
    `-- obj
        `-- com
            `-- example
                `-- util
                    `-- Hello.class
    19 directories, 6 filesHTH,
    David

  • How to run a java program using additional jar files

    Hi everyone in the forum,
    i ve created an app using the hFreeChart in eclipse, so i added them as external jar files and tested the program.
    now my problem is that the program should run using a terminal in win and i do not know how can i do to make the command line or the system to find them, i added to the path but i read somtehing about classpath, but i have no idea. if anyone can help?
    thanks in advanced

    Actually, the best way to prepare a program for regular running is to make it an executable jar file, which means adding a manifest file which contains (at least) a Main-class: and a Class-Path: line. Referenced class libraries typically sit in a lib directory next to the java file. Then you can run it using java -jar myprog.jar.
    Failing that create a batch file or link that supplied java with command line parameters including a -classpath=
    Using the class path environment results in too much contention between competing values of it.

  • How to use external jar files ??

    Hi all,
    In my user-defined function for mapping (IR) , I want to make use a Class which is available in an external .jar file.
    Our XI is working on Windows2003 OS. I set the classpath in OS environment variables.
    But it is not working.
    Where I should set the classpath ?
    Can anyone help.
    Thanks in Advance
    Chemmanz
    Message was edited by: Chemmanz

    Hi Chemmanz,
    For user defined functions, it is not necessary to use the external jar files.
    Just follow the below steps:
           1.      To create a new user-defined function, choose <b>Create New Function</b> in the data-flow editor at the bottom of the screen, on the left-hand side.
           2.      Specify the attributes of the new function in the subsequent window:
    Name:
    Technical name of the function. The name is displayed in the function chooser and on the data-flow object.
    Description:
    Description of how the function is used.
    Arguments:
    In this table, you specify the number of input values the function can process, and name them. All functions are of type String.
           3.      In the subsequent window, you can create Java source code:
                                a.      You can import Java packages to your methods from the Imports input field, by specifying them separated by a comma or semi-colon:
    You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since all message mappings require these packages and therefore import them.
    In addition to the standard packages, you can also specify Java packages that you have imported as archives and that are located in the same, or in an underlying software component version as the message mapping.
                                b.      Create your Java source text in the editor window or copy source text from another editor.
           4.      Confirm with Save and Close.
           5.      User-defined functions are limited to the message mapping in which you created the function. To save the new function, save the message mapping.
           6.      To test the function, use the test environment.
    The new function is now visible in the User-Defined function category. When you select this category, a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the function to the data-flow editor, choose the arrow next to the button and select from the list box displayed.
    Regards,
    Prasad U

  • How to reuse a jar file in another application

    i have created a jar file.Now i want to reuse this jar file in another java program.Could anyone please guide me with the steps of how to reuse a jar file

    i have created a jar file.Now i want to reuse this
    jar file in another java program.Could anyone please
    guide me with the steps of how to reuse a jar fileput your jar file in class path and import the class which u want to reuse in your code so that u can access all the methods in that class in ur code.

  • How to use a jar file

    Hi Everybody!
    waits for "Hi Dr.Nick" I need a program that will extract the text from a PDF and I think I may have found it here: http://multivalent.sourceforge.net/Tools/index.html
    However the instructions are a bit wacky and don't seem to work. My goal here is to extract the text from a pdf document so I am going by these instructions: http://multivalent.sourceforge.net/Tools/doc/ExtractText.html
    Currently when I follow the instructions and try to run "java tool.doc.ExtractText a.pdf" I recieve a ClassNotFoundException. the jar file I am using(Multivalent.jar) is currently located is /home/myusername/prog and the current CLASSPATH is also /home/username/prog. Can someone please explain to me what I am doing wrong?
    kthxbye

    Oblivious0823 wrote:
    Currently when I follow the instructions and try to run "java tool.doc.ExtractText a.pdf" I recieve a ClassNotFoundException. the jar file I am using(Multivalent.jar) is currently located is /home/myusername/prog and the current CLASSPATH is also /home/username/prog. Can someone please explain to me what I am doing wrong?You haven't set your classpath correctly. It should include the jar file.

Maybe you are looking for

  • A button with more than one label... how?

    hi everyone!! i have a little problem... i have to create a button with 3 labels... and i've no idea about how... i tried to add labels to button but it's not permitted... plz tell me how to reach a result like this:               | label1           

  • Capturing video using XLR8's InterView device?

    Since I prefer the QT software to the InterView software that came with my S-video to USB capture device... Is there a way to use QTPro instead?

  • Aggregation at cube

    Hi All, I am loading Transaction data into my cube from flat file. My requirement is: There are 2 doc's: x--10--10/10/2008                            x---20-26/10/2008 Here when i load for the month these both get aggregated. And I need the date fiel

  • Custom Report currency is missing in Total price

    Dear BC Community. When making a Custom Report, the "Total Price" tab doesn't show the currency the order was purchased in. How do I fix this? - Or is it a bug in BC?

  • Excel option is displaying blank Excel in Report output

    Hi All, We have created the ALV report and everything is working fine except the Excel icon in the report output screen. When we are clicking on the excel icon it is displaying the blank excel. In our systems MS Office 2007 has been installed. Is the