Purpose of jar file

what is a jar file.
what is it s purpose and where isit used
thank you

Bookmark this page, then whenever you get an urge to ask a basic Java question, check there first.
http://java.sun.com/j2se/1.4.1/docs/index.html
Do a search on this page for "jar".

Similar Messages

  • Purpose of .jar

    Hello,All !
    I am a begaining of java learner.I want to know about the purpose of .jar file.
    And which way I should use for changing .jar file in eclipse platform.If you know,please tell me.
    Thanks.

    JAR "java archive" file lets you compress your various files, of a project.
    JAR is a special format that can be used by Java technologies to transfer, read numerous files of a given application / project at a single go.
    Ex: An mobile device can download a single jar file that can represent a whole application. Because jar compresses .class files, image files, etc. - the download is much faster. The mobile device program then unzips and executes the .class files - letting you have faster access to your downloaded application.
    Google "define:jar" to get more information on JAR

  • Adding JAR file to project

    Hi All
    How can i add jar to my project environment.
    Actually what i did was.
    Created one folder called "JavaWork" like d:\JavaWork
    and put the jar file into this folder and wrote a test class which is importing some classes from the jar file.
    how to use jar ? Please someone help me.
    Thanks in advance
    Shan

    `man jar`
    jar(1) jar(1)
    NAME
    jar - Java archive tool
    SYNOPSIS
    jar [ -C ] [ c ] [ f ] [ i ] [ M ] [ m ] [ O ] [ t ] [ u ]
    [ v ]
    [ x file ] [ manifest-file ] destination input-file
    [ input-files ]
    DESCRIPTION
    The jar tool is a Java application that combines multiple
    files into a single JAR archive file. It is also a gen-
    eral-purpose archiving and compression tool, based on ZIP
    and the ZLIB compression format. However, jar was
    designed mainly to facilitate the packaging of Java
    applets or applications into a single archive. When the
    components of an applet or application (.class files,
    images and sounds) are combined into a single archive,
    they can be downloaded by a Java agent (like a browser) in
    a single HTTP transaction, rather than require a new con-
    nection for each piece. This dramatically improves down-
    load time. The jar tool also compresses files, which fur-
    ther improves download time. In addition, it allows indi-
    vidual entries in a file to be signed by the applet author
    so that their origins can be authenticated. The syntax
    for the jar tool is almost identical to the syntax for the
    tar(1) command. A jar archive can be used as a class path
    entry, whether or not it is compressed.
    The three types of input files for the jar tool are:
    o Manifest file (optional)
    o Destination jar file
    o Files to be archived
    Typical usage is:
    example% jar cf myjarfile *.class
    In this example, all the class files in the current direc-
    tory are placed in the file named myjarfile. A manifest
    file is automatically generated by the jar tool and is
    always the first entry in the jar file. By default, it is
    named META-INF/MANIFEST.MF. The manifest file is the
    place where any meta-information about the archive is
    stored. Refer to the Manifest Format in the SEE ALSO sec-
    tion for details about how meta-information is stored in
    the manifest file.
    To use a pre-existing manifest file to create a new jar
    archive, specify the old manifest file with the m option:
    example% jar cmf myManifestFile myJarFile *.class
    When you specify cfm instead of cmf (that is, you invert
    the order of the m and f options), you need to specify the
    name of the jar archive first, followed by the name of the
    manifest file:
    example% jar cfm myJarFile myManifestFile *.class
    The manifest uses RFC822 ASCII format, so it is easy to
    view and process manifest-file contents.
    OPTIONS
    The following options are supported:
    -C Changes directories during execution of the jar com-
    mand. For example:
    example% jar uf foo.jar -C classes *
    c Creates a new or empty archive on the standard out-
    put.
    f The second argument specifies a jar file to process.
    In the case of creation, this refers to the name of
    the jar file to be created (instead of on stdout).
    For table or xtract, the second argument identifies
    the jar file to be listed or extracted.
    i Generates index information for the specified jar
    file and its dependent jar files. For example,
    example% jar i foo.jar
    would generate an INDEX.LIST file in foo.jar which con-
    tains location information for each package in foo.jar and
    all the jar files specified in foo.jar's Class-Path
    attribute.
    M Does not create a manifest file for the entries.
    m Includes manifest information from specified pre-
    existing manifest file. Example use:
    example% jar cmf myManifestFile myJarFile *.class
    You can add special-purpose name-value attribute
    headers to the manifest file that are not contained
    in the default manifest. Examples of such headers
    are those for vendor information, version informa-
    tion, package sealing, and headers to make JAR-bun-
    dled applications executable. See the JAR Files
    trail in the Java Tutorial and the JRE Notes for
    Developers web page for examples of using the m
    option.
    O Stores only, without using ZIP compression.
    t Lists the table of contents from standard output.
    u Updates an existing JAR file by adding files or
    changing the manifest. For example:
    example% jar uf foo.jar foo.class
    adds the file foo.class to the existing JAR file
    foo.jar, and
    example% jar umf foo.jar
    updates foo.jar's manifest with the information in
    manifest.
    v Generates verbose output on stderr.
    x file
    Extracts all files, or just the named files, from
    standard input. If file is omitted, then all files
    are extracted; otherwise, only the specified file or
    files are extracted.
    If any of the files is a directory, then that direc-
    tory is processed recursively.
    EXAMPLES
    To add all of the files in a particular directory to an
    archive:
    example% ls
    0.au 3.au 6.au 9.au at_work.gif
    1.au 4.au 7.au Animator.class monkey.jpg
    e.au 5.au 8.au Wave.class spacemusic.au
    example% jar cvf bundle.jar *
    adding: 0.au
    adding: 1.au
    adding: 2.au
    adding: 3.au
    adding: 4.au
    adding: 5.au
    adding: 6.au
    adding: 7.au
    adding: 8.au
    adding: 9.au
    adding: Animator.class
    adding: Wave.class
    adding: at_work.gif
    adding: monkey.jpg
    adding: spacemusic.au
    example%
    If you already have subdirectories for images, audio
    files, and classes that already exist in an HTML direc-
    tory, use jar to archive each directory to a single jar
    file:
    example% ls
    audio classes images
    example% jar cvf bundle.jar audio classes images
    adding: audio/1.au
    adding: audio/2.au
    adding: audio/3.au
    adding: audio/spacemusic.au
    adding: classes/Animator.class
    adding: classes/Wave.class
    adding: images/monkey.jpg
    adding: images/at_work.gif
    example% ls -l
    total 142
    drwxr-xr-x 2 brown green 512 Aug 1 22:33 audio
    -rw-r--r-- 1 brown green 68677 Aug 1 22:36 bundle.jar
    drwxr-xr-x 2 brown green 512 Aug 1 22:26 classes
    drwxr-xr-x 2 brown green 512 Aug 1 22:25 images
    example%
    To see the entry names in the jar file using the jar tool
    and the t option:
    example% ls
    audio bundle.jar classes images
    example% jar tf bundle.jar
    META-INF/MANIFEST.MF
    audio/1.au
    audio/2.au
    audio/3.au
    audio/spacemusic.au
    classes/Animator.class
    classes/Wave.class
    images/monkey.jpg
    images/at_work.gif
    example%
    To display more information about the files in the
    archive, such as their size and last modified date, use
    the v option:
    example% jar tvf bundle.jar
    145 Thu Aug 01 22:27:00 PDT 1996 META-INF/MANIFEST.MF
    946 Thu Aug 01 22:24:22 PDT 1996 audio/1.au
    1039 Thu Aug 01 22:24:22 PDT 1996 audio/2.au
    993 Thu Aug 01 22:24:22 PDT 1996 audio/3.au
    48072 Thu Aug 01 22:24:23 PDT 1996 audio/spacemusic.au
    16711 Thu Aug 01 22:25:50 PDT 1996 classes/Animator.class
    3368 Thu Aug 01 22:26:02 PDT 1996 classes/Wave.class
    12809 Thu Aug 01 22:24:48 PDT 1996 images/monkey.jpg
    527 Thu Aug 01 22:25:20 PDT 1996 images/at_work.gif
    example%
    If you bundled a stock trade application (applet) into the
    following jar files,
    main.jar buy.jar sell.jar other.jar
    and you specified the Class-Path attribute in main.jar's
    manifest as
    Class-Path: buy.jar sell.jar other.jar
    then you can use the i option to speed up your applica-
    tion's class loading time:
    example$ jar i main.jar
    An INDEX.LIST file is inserted in the META-INF directory
    which will enable the application class loader to download
    the right jar files when it is searching for classes or
    resources.
    SEE ALSO
    keytool(1)
    JAR Files @
    http://java.sun.com/docs/books/tutorial/jar/
    JRE Notes @
    http://java.sun.com/j2se/1.3/runtime.html#exam-
    ple
    JAR Guide @
    http://java.sun.com/j2se/1.3/docs/guide/jar/index.html
    For information on related topics, use the search link @
    http://java.sun.com/
    13 June 2000 jar(1)

  • How to bundle java help class into jar file ?

    Hi, all,
    I have some package in my project, with which I have a java help jar file as classpath, when I run my project, I need the jh.jar file in directory /jar/jh.jar.
    Now, I bundled all my class packages into a jar file, my.jar, together with the /jar directory. When i run my jar file with command:
    java -jar my.jar
    It tells me couldn't find javahelp class.
    What shall I do? How can I create my jar file with the jh.jar?
    Thanks in advance.

    I think you'd be better off just adding the jh.jar as
    a classpath argument and running it like that:
    java -classpath /myjavalibdir/jh.jar -jar myjar.jar
    ...otherwise you're stepping into redistribution of
    binary issues licensing-wise. That won't work either; when you run java with the -jar option, it ignores both the -classpath option and the CLASSPATH environment variable. However, it will see jh.jar automatically if you put it in the <path-to-java>/jre/lib/ext directory. But for distribution purposes, it might be simpler just to combime the contents of jh.jar into myjar.jar (if you use Ant, its <jar> task makes that very easy). Or, you can just run it this way:java -classpath myjar.jar;jar/jh.jar MyMainClassBTW, I don't think redistribution is a problem; otherwise how anyone even use JavaHelp?

  • Why can't I read any of my resources in a jar file?

    For an application I was developing, I wanted to create a Binary File using the following code:
    DataInputStream in = null;
            try {
                File file = new File(name);
                in = new DataInputStream(
                        new BufferedInputStream(
                            new FileInputStream(file)));
            } catch (FileNotFoundException e) {
                System.out.println("Non-existential File.");
                System.exit(0);
    }I am using Netbeans 6.5.1., and it groups my projects so that there are folders for build, src, dist, nbproject inside the project folder. The application that I am developing is a graphics demo that requires the use of several text files to represent the maps, so I wanted to read them using a FileInputStream.
    I kept this file, "islandmap.txt", in the src folder in my project. In the method above, I coded my program so that the "name" would be "src\islandmap.txt", and it read from the file perfectly. However, I needed to compile it to a Jar file too. After doing that, the program no longer functioned. I remembered when I used a tutorial long ago that used
    URL url = getClass().getClassLoader().getResource(fileName) ... in order to get the directory of the files. That made sense, because a person who is running the program via Java Webstart or a Jar Executable would definitely not have the parts of the program located in the same directory, so the code is used to find where the java program is. However, I realized something...
    File file = new File( - constructor - )There are four constructors for files, and I only think I could use two. The first is using a string, like I have done before with "src\islandmap.txt." Now, the URL url = getClass().getClassLoader().getResource(fileName) part, it was used before to locate a URL in order to open a buffered image. The constructor for File does not support URLs, but instead supports URIs.I tried converting between the two, changing a URL into a string, and producing a URI from the string. But it did not work, giving me an error that URI was not hierarchical. And that's when I realized that they were certainly not interchangable.
    More specifically, here is my code as of now:
    public boolean loadMap(String mapName) {
            String path = "src/islandmap.txt";   //This is where the map files are stored
            mapName = getClass().getClassLoader().getResource(path).getPath(); //getPath changes the URL into a String
            DataInputStream in = null;
            try {
                File file = new File(mapName);
                in = new DataInputStream(
                        new BufferedInputStream(
                            new FileInputStream(file)));
                 //code to actually read from the file goes here
            } catch (FileNotFoundException e) {
                System.out.println("Non-existential File.");
                System.exit(0);
            } finally {
                 //close in
    }So that is my problem now. I am stuck. For my purposes, I basically must use a stored text file within my jar, but I don't know how to read it. It distresses me that normally, I already know how to open images that are located inside my src folder using URLs, but not any other file requiring a File class to be wrapped within a Buffered Writer/Reader. Could somebody please assist me with this, or suggest an alternative that would also fall under my conditions? I would appreciate it so much. Thank you.
    Edited by: celestialsalt on Dec 6, 2009 5:29 PM
    Edited by: celestialsalt on Dec 6, 2009 5:49 PM

    Start with
    URL url = getClass().getClassLoader().getResource(fileName)Then observe that URL has a [openStream()|http://java.sun.com/javase/6/docs/api/java/net/URL.html#openStream()] method that will give you an InputStream. Since you are reading text you might want to create an InputStreamReader from which you can do your reading much like you used the FileReader before when you were working with a File.
    Class also has a [getResourceAsStream()|http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)] which combines the first two steps into one. Ie use getResource() as you mentioned when you want to get a URL that some other class will use to read (eg an image) or use getResourceAsStream() when you are going to do the reading yourself.

  • Target to execute multiple junit tests from jar file

    I have written a custom selenium framework using JUnit and Selenium, problem I am having right now is our team wants to run the tests inside HP Quality Center (I have no idea or any experience with Quality Center) but if I provide a jar file the them they can execute it inside the Quality Center (Reason to run it in Quality Center is for reporting purpose).
    Problem is that I have created my framework in away that You can create multiple JUnit base test files for different tests also keep in mind that these classes dont need main method (This is where the problem when it comes to jaring up ). I have introduced following ant target to run all the test cases.
         <target name="test.selenium" depends="jar" description="target to execute all the selenium tests.">
              <junit printsummary="yes">
                   <classpath>
                        <path refid="classpath"/>
                        <path refid="application"/>
                   </classpath>
                   <batchtest fork="yes">
                        <fileset dir="${src.dir}" includes="**/Test*Selenium.java"/>
                   </batchtest>
              </junit>
         </target>above ant target runs without any problem, but when you jar it up you need a manifest and main class, is there away I cant introduce some attribute that can execute all my tests without adding main method to each of them.
    Here is my ant target for jar
         <target name="jar" depends="compile"
                   description="Generates final jar">
              <copy todir="${build.jar}">
                   <fileset dir="lib" excludes="**/*.java"/>
              </copy>
              <jar jarfile="${build.jar}/yukonSelenium.jar"
                        basedir="${build.classes}">
                   <manifest>
                        <attribute name="Main-Class" value="com.somepackage.selenium.test.TestAuthenticationSelenium"/>
                        <attribute name="Class-Path"
                             value=". /c:/build/jar/log4j-1.2.15.jar /c:/build/jar/junit-4.6.jar /c:/build/jar/selenium-java-client-driver.jar /c:/build/jar/dom4j-1.6.1.jar"/>
                   </manifest>
              </jar>
         </target>And this is how the Test Class looks like, I have added main method in this but once i do this after jaring java -jar myJarfile.jar will only execute just the class i have main method init.
    public class TestAuthenticationSelenium extends SomePrivateFrameWorkClass {
         private void init() {
              start();
         @Test
         public void testProductNav() {
                //somecode
         @Test
         public void multipleLogin() throws FileNotFoundException, InterruptedException {
                             //Some Code
         public static void main(String[] args) {
              org.junit.runner.JUnitCore.main("com.somepackage.selenium.test.TestAuthenticationSelenium");
    }Please let me know if i should put the entire ant build file.
    Thanks for any help.
    anuradha.uduwage
    Edited by: Tilter on Aug 24, 2009 10:05 PM
    Edited by: Tilter on Aug 24, 2009 10:06 PM

    What i mean is if i have 3 class files in my jar file, and each one of those classes has a main method, how will i be able to execute a class of my choice from that jar file. In manifest files, you specify the main class, but how would i specify multiple classes with main methods, or achieve my objective here.

  • Jar files for jms websphere

    Hello Experts,
    We are trying to establish connection between PI and webshpere ,for that we are using JMS adapter.
    And in the channel we are getting the error as:
    Error connecting due to missing class: com.ibm.websphere.naming.WsnInitialContextFactory. Ensure that all resources required are present in the JMS provider library: com.sap.aii.adapter.lib.sda
    Can anyone please provide me the required jar files or the path from where i can download the .jar files required for this purpose.
    Regards
    Naveen

    Hi,
    Thanks for your reply ,i have installed 2 jar files:
    naming .jar and
    javax.j2ee.connector.jar.
    But still geting the error as :
    Channel error occurred. Detailed error (if any) : com.sap.aii.adapter.jms.api.connector.ConnectorException: Error creating initial context with environment: {java.naming.provider.url=iiop://xyz, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory, java.naming.security.principal=xyz, java.naming.security.credentials=xyz}for profile: ConnectionProfile of channel: JMSSender_MESon node: xyz having object id: xyz: javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory<br> at com.sap.aii.adapter.jms.core.connector.JndiConnectorImpl.createInitialContext(JndiConnectorImpl.java:65)<br> ...
    Urgent help required..
    Thanks

  • Jar files are not read from HDD

    Hi,
    we are facing a problem while trying to read jar files from Hard disk using CVM. we could able to read the file and the number of bytes read exactely matches with the file size. but while trying to use JNI (*env)->FindClass it is returns 0. Some times it returns an error "inflateFully: ZIP_Read". however we could able to read a small jar file which is of 2 kb and display some graphics. is it the problem with size?? our application is 80kb.Can some one help us in fixing this.
    Profile: PBP/CDC
    Note:
    Sam

    Step 6 makes your third party jars available during runtime on your server since you put the dependency to runtime. I don't think you need/can reference your j2ee server dc in the portalapp.xml.
    Summary of the link I sent you:
    1. Create an External Library DC
    2. Copy all of the Jars I needed to the libraries folder of this DC
    3. Create two Public Parts (right click on the jar files in Package Explorer)
          i) compilePart (with purpose compilation)
          ii) assemblyPart (with purpose assembly)
    4 Create a new DC of type J2EE Server Component / Library
    5. Add a Used DC to the J2EE Library, reference the compilePart from previous step, and set Dependency type to Build
    6. Add another Used DC, reference the assemblePart, this time select both Build and Runtime Dependency Types
    7. Build and deploy.
    Br
    Göran

  • Jar file in applet not saved in internet files when using jdk plugin

    Hello,
    I recently upgarded to jdk1.3.1 and converted our applet and classes to jdk1.3.1 using swing classes. From there, we converted the html file with htmlconverter and diployed this on the web. When a user goes to the web, the system automatically downloads the java plugins and installs them on the clients maching. From there our jar file loads and executes. Our applet runs fine. However, every time our website is accessed, our jar file cookie must be downloaded which is just over 1meg and I know this is not going to fly with our clients.
    What needs to be done so the jar file is not downloaded every time, to work like java version 1.x ?
    Thanks for your help in advance with this one.
    Jay Ford

    Hi Jay Ford,
    Enable the "Recycle Classloader" in Control Panel-->Java Plug-in1.3.1-->Basic.
    The main purpose of this Recycle classloader is it will enable the "javaplugin.classloader.cache.enabled" property to true and it caches the jar files for performance enchancement.
    Hope this will help you.
    Anil.
    Developer Technical Support,
    Sun Microsystems Inc,
    http://www.sun.com/developers/support

  • Problem accessing class in jar file

    Hello. I am trying to create a jar file from my already compiled classes. I have around 5 packages, and my programs' entry point is in one of the packages, we'll call package A. Each package has its own purpose and package A calls any needed package to perform their task. This works well when I compile, run and all. However, when I create a jar file, it only works with the local package and any calls to another package do not work. How can I get around this? any help will be appreciated

    This is the output..
    05/05/2010  10:19 AM        10,946,787 MYJAR.jar
                   1 File(s)     10,946,787 bytes
                   0 Dir(s)   1,434,251,264 bytes freeMy manifest file contains
    Manifest-Version: 1.0
    Class-Path: .
    Main-Class: Login.loginMain
    AndrewThompson64 wrote:Is the code [swallowing exceptions|http://pscode.org/javafaq.html#stacktrace] at any point?
    Nope..
    AndrewThompson64 wrote:
    How do you know that if there is absolutely no error output?The when I ran the code from my compiler, it has no errors, and it works smoothly. I have used a JAR for a single package program before and it worked well but this multiple package program is giving me the problem and I don't want to put all the files in a single package

  • Add a jar file to Java load path at run time

    Hi
    I loaded my file successfully , but when I tried to use the driver to connect to the DB , I get
    java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
    Here is my class
    import java.net.URL;
    import java.io.IOException;
    import java.net.URLClassLoader;
    import java.net.MalformedURLException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.io.*;
    public class JarFileLoader1 extends URLClassLoader
    public JarFileLoader1 (URL[] urls)
    super (urls);
    public void addFile (String path) throws MalformedURLException
    String urlPath = "jar:file://" + path + "!/";
    addURL (new URL (urlPath));
    public static void main (String args[])
    try
    File f = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc.jar");
    System.out.println("%%%% " + f.exists());
    File f1 = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc_license_cu.jar");
    System.out.println("%%%% " + f1.exists());
    File f2 = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc4.jar");
    System.out.println("%%%% " + f2.exists());
    URL urls [] = {};
    JarFileLoader1 cl = new JarFileLoader1 (urls);
    cl.addFile ("E:\\db2_v9_5 FP5_drivers\\db2jcc.jar");
    cl.addFile ("E:\\db2_v9_5 FP5_drivers\\db2jcc_license_cu.jar");
    cl.addFile ("E:\\db2_v9_5 FP5_drivers\\db2jcc4.jar");
    URL url = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc.jar").toURL();
    URLClassLoader clazzLoader = new URLClassLoader(new URL[]url);
    Class clazz = clazzLoader.loadClass("com.ibm.db2.jcc.DB2Driver");
    System.out.println ("Success! --> " + clazz.newInstance().toString());
    String connectString = "jdbc:db2://dummy:34000/dev1";
    System.out.println("BEFORE CONNECTION");
    Connection conn =
    DriverManager.getConnection(connectString,"mario","123123");
    System.out.println("after CONNECTION");
    System.out.println("Driver Version - " + conn.getMetaData().getDriverVersion() + "
    catch (Exception ex)
    System.out.println ("In Exception Block -- Failed.");
    ex.printStackTrace (System.out);
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    Here are the logging messages
    %%%% true
    %%%% true
    %%%% true
    Success! --> com.ibm.db2.jcc.DB2Driver@24442444
    BEFORE CONNECTION
    In Exception Block -- Failed.
    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:186)
    at com.tdbfg.tdsecurities.kasper.admin.aboutkasper.JarFileLoader1.main(JarFileLoader1.java:61)

    kasper123 wrote:
    Hi
    I loaded my file successfully , but when I tried to use the driver to connect to the DB , I get
    java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
    Here is my class
    import java.net.URL;
    import java.io.IOException;
    import java.net.URLClassLoader;
    import java.net.MalformedURLException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.io.*;
    public class JarFileLoader1 extends URLClassLoader
    public JarFileLoader1 (URL[] urls)
    super (urls);
    public void addFile (String path) throws MalformedURLException
    String urlPath = "jar:file://" + path + "!/";
    addURL (new URL (urlPath));
    public static void main (String args[])
    try
    File f = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc.jar");
    System.out.println("%%%% " + f.exists());
    File f1 = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc_license_cu.jar");
    System.out.println("%%%% " + f1.exists());
    File f2 = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc4.jar");
    System.out.println("%%%% " + f2.exists());
    URL urls [] = {};
    JarFileLoader1 cl = new JarFileLoader1 (urls);
    cl.addFile ("E:\\db2_v9_5 FP5_drivers\\db2jcc.jar");
    cl.addFile ("E:\\db2_v9_5 FP5_drivers\\db2jcc_license_cu.jar");
    cl.addFile ("E:\\db2_v9_5 FP5_drivers\\db2jcc4.jar");
    URL url = new File("E:\\db2_v9_5 FP5_drivers\\db2jcc.jar").toURL();
    URLClassLoader clazzLoader = new URLClassLoader(new URL[]{url});
    Class clazz = clazzLoader.loadClass("com.ibm.db2.jcc.DB2Driver");
    System.out.println ("Success! --> " + clazz.newInstance().toString());
    String connectString = "jdbc:db2://dummy:34000/dev1";
    System.out.println("BEFORE CONNECTION");
    Connection conn =
    DriverManager.getConnection(connectString,"mario","123123");
    System.out.println("after CONNECTION");
    System.out.println("Driver Version - " + conn.getMetaData().getDriverVersion() + " ");
    catch (Exception ex)
    System.out.println ("In Exception Block -- Failed.");
    ex.printStackTrace (System.out);
    }================================================
    ====================================================
    Here are the logging messages
    %%%% true
    %%%% true
    %%%% true
    Success! --> com.ibm.db2.jcc.DB2Driver@24442444
    BEFORE CONNECTION
    In Exception Block -- Failed.
    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:186)
    at com.tdbfg.tdsecurities.kasper.admin.aboutkasper.JarFileLoader1.main(JarFileLoader1.java:61)
    For debugging purposes you could use [DriverManager.getDrivers()|http://download.oracle.com/javase/6/docs/api/java/sql/DriverManager.html#getDrivers%28%29] to get an enumeration of all drivers
    and then output their names.
    Maybe, with the classloader malarkey you are doing
    you need to use [DriverManager.registerDriver(Driver driver)|http://download.oracle.com/javase/6/docs/api/java/sql/DriverManager.html#registerDriver%28java.sql.Driver%29]

  • When to use JAR files

    We are having a discussion at work about the proper usage of jar files. I am fairly opinionated and need to get some good feedback on when jar files make sense.
    Network:
    We have a unix based network as well as a windows based network. We can share samba mounted drives and allow windows access to the class files on the unix network. Most of our internal webservers are on the unix platform.
    We use java in applications, servlets, and JSP's. We have also designed an electronic technical manual that will be deployed via internet and cd rom.
    My first contention that jar files are not needed in the Servlet environment. The class files are virtually local and file storage is not an issue.
    My second contention is that applications running on windows machines would have better performance from local jar files, but the benefits are outweighed by the need to rebuild and reinstall the jar files to ensure the applications behaved the same on both systems.
    My third contention is that the technical manual on cd is a very good candidate for use of jars. We have a limited amount of space to store the files on a cd. We would probably use the jars to serve the information to ensure the behavior of the manual is the same whether the application was access via the CD or the internet.
    What am I missing? Is my understanding of JAR files out of whack with reality?

    Jar files (and their siblings i.e. Wars, Ears) make a
    good unit of deployment. It is much easier to keep
    track of a few jars than a bunch or classes.We have classes which are used in several applications. Ie, A bean queries our bill of material. It is used in an engineering, a manufacturing and a planning application. It can also be used in a jsp. If that bean changes, we would have to deploy three new jar files. If we run from one directory structure, a simple compile fixes all three applications.
    With the samba mounts, we can get to the directory from windows and most flavors of unix.
    We actually have two directory structures. One for production and one for test. Developers usually have another copy stashed somewhere for development purposes.
    I don't know where you get better performance. The
    jar needs to be unzipped which can only slow
    performance. Rebuilding a jar is easy (get Ant) and
    reinstalling a jar is easier than installing a buch of
    class files and resources (see above.) In addition,
    you can seal jars which gives you some level of
    protection (though superficial) and you can set up the
    jar so that it knows the main class.For the most part, these are internal applications, so security is not the top priority. Jars would be nice as they should generate less network traffic due to their smaller size.
    A jar is really just a zip file with a special
    structure. This is really a question of whether you
    need compression. If you can't fit everything onto a
    single CD then compression can help. A plain old zip
    file would work just as well.The compression is the main reason for the techpub application using the jar files. Space on the CD is a concern. Also, for internet access, bandwidth is also a concern. IE, less bits to shove down the wire.
    Like I said before jars are a convienient way to keep
    things organized. You can send out a program in a
    single unit that has everything it needs to run.I have an aversion to anything which requires an install on the users box. This probably comes from working with a bunch of unix hacks that have our system tuned to the nth degree. Much easier to deploy to one central location. No worries about whether or not someone turned their machine off before the nightly push, who has admin rights, etc. Map to the drive and you are off and running. One big performance hit is running the jvm from a shared drive. The JVM should be installed locally.

  • Packaging POF object class in a jar file

    I have the following issue packaging a POF class.
    I have two POF classes which are defined in the package oracle.communications.activation.asap.ace;
    1. Token.java
    2. Asdl.java
    For simplicity i package them in the coherence.jar along with the other nessary artifacts.
    "tokens-pof-config.xml"
    <?xml version="1.0"?>
    <pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
    xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config coherence-pof-config.xsd">
    <user-type-list>
    <!-- coherence POF user types -->
    <include>coherence-pof-config.xml</include>
    <!-- com.tangosol.examples package -->
    <user-type>
    <type-id>1001</type-id>
    <class-name>Token</class-name>
    </user-type>
    <user-type>
    <type-id>1002</type-id>
    <class-name>Asdl</class-name>
    </user-type>
    </user-type-list>
    <allow-interfaces>true</allow-interfaces>
    <allow-subclasses>true</allow-subclasses>
    </pof-config>
    Then I startup the CacheServer it startsup fine. However when I invoke the POF classes from my weblogic artifacts I get the following error message.
    <Oct 26, 2011 10:04:24 PM PDT> <Warning> <EJB> <BEA-010065> <MessageDrivenBean threw an Exception in onMessage(). The exception was:
    (Wrapped) java.io.IOException: unknown user type: oracle.communications.activation.asap.ace.Token.
    (Wrapped) java.io.IOException: unknown user type: oracle.communications.activation.asap.ace.Token
    ======================================================================================================================
    If I however define the classes in the default package or no package instead of package oracle.communications.activation.asap.ace;
    Keeping everything else the same everything works fine.
    ====================================================================================
    What do I need to do to make this work if I am packaging my POF classes not in the default package ?

    Hi JK,
    Well i have modified my POF classes since then and now created a package for them before I was just playing around and had them defined in a default package.
    Second Baby steps here, once I get things working by packaging things in the coherence.jar file I will create my own jar artifact and add it to class path. As it is I have classpath issues. ...
    So as I mentioned earlier.
    I created the oracle/communications/activation/asap/ace directory added my two POF classes to it and then repackaged the jar.
    It returns this error!
    2011-10-27 06:48:03.355/4.696 Oracle Coherence GE 3.6.0.4 <Error> (thread=main, member=1): Error while starting service "DistributedCache": (Wrapped) (Wrapped: error configuring class "com.tangosol.io.pof.ConfigurablePofContext") java.lang.NoClassDefFoundError: oracle/communications/activation/asap/ace/Token (wrong name: Token)
    So any ideas ?
    "tokens-pof-config.xml"
    ==============
    <?xml version="1.0"?>
    <pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
    xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config coherence-pof-config.xsd">
    <user-type-list>
    <!-- coherence POF user types -->
    <include>coherence-pof-config.xml</include>
    <!-- com.tangosol.examples package -->
    <user-type>
    <type-id>1001</type-id>
    <class-name>oracle.communications.activation.asap.ace.Token</class-name>
    </user-type>
    <user-type>
    <type-id>1002</type-id>
    <class-name>oracle.communications.activation.asap.ace.Asdl</class-name>
    </user-type>
    </user-type-list>
    <allow-interfaces>true</allow-interfaces>
    <allow-subclasses>true</allow-subclasses>
    </pof-config>
    cache-server.sh_
    #!/bin/sh
    # This will start a cache server
    # specify the Coherence installation directory
    COHERENCE_HOME=.
    # specify the JVM heap size
    MEMORY=512m
    if [ ! -f ${COHERENCE_HOME}/bin/cache-server.sh ]; then
    echo "coherence.sh: must be run from the Coherence installation directory."
    exit
    fi
    if [ -f $JAVA_HOME/bin/java ]; then
    JAVAEXEC=$JAVA_HOME/bin/java
    else
    JAVAEXEC=java
    fi
    #JAVA_OPTS="-Xms$MEMORY -Xmx$MEMORY -Dtangosol.pof.enabled=true -Dtangosol.pof.config=tokens-pof-config.xml"
    #JAVA_OPTS="-Xms$MEMORY -Xmx$MEMORY -Dtangosol.coherence.clusteraddress=224.3.6.0 -Dtangosol.coherence.clusterport=3059"
    JAVA_OPTS="-Xms$MEMORY -Xmx$MEMORY"
    #JAVA_OPTS="-Xms$MEMORY -Xmx$MEMORY"
    $JAVAEXEC -server -showversion $JAVA_OPTS -cp "$COHERENCE_HOME/lib/coherence.jar:." com.tangosol.net.DefaultCacheServer $1
    Token.java for example (Asdl.java looks very similar)
    ================================
    package oracle.communications.activation.asap.ace;
    import java.io.IOException;
    import java.io.Serializable;
    import com.tangosol.io.pof.PortableObject;
    import com.tangosol.io.pof.PofReader;
    import com.tangosol.io.pof.PofWriter;
    import java.sql.*;
    import java.util.Enumeration;
    * This class represents the domain object Token. This class is also packaged on the classpath
    * for the Cache-Server when it starts up. The Token class implements the PortableObject format.
    * @author Ankit Asthana
    public class Token implements PortableObject {
         * The state associated with a token
         * 1 - Unassigned, 2 - Available, 3 - Reserved, 4 - defunct
         private int state;
         * The network ID associated with each token
         private String neID;
         * Unique Token ID, used to identify Tokens
         private String tokenID;
         * State of the token possible
         public static int TOKEN_AVAILABLE = 2;
         public static int TOKEN_RESERVED = 3;
         * The following are static final indices required for the implementation
         * for a POF object, they have to be sequential in order.
         public static final int TOKENID = 0;
         public static final int STATE = 1;
         public static final int NEID = 2;
         * setter Method for state of the token
         * @param state
         public void setState(int state) {
              this.state = state;
         * getter Method for the state of the token
         * @return
         public int getState() {
              return state;
         * setter Method for the network ID
         * @param neID
         public void setNeID(String neID) {
              this.neID = neID;
         * getter Method for the network ID
         * @return
         public String getNeID() {
              return neID;
         * returns the TokenID for the current token
         * @return
         public String getTokenID() {
              return tokenID;
         * Default Constructor required by POJO's, Do not remove!
         public Token() {
         * This is a utility method and returns the state of the token in a String format using the
         * integer value representing the state of the token passed to it.
         * @param tokenStateInteger
         * @return
         public static String tokenToString(int tokenStateInteger) {
              if (tokenStateInteger == TOKEN_AVAILABLE)
                   return "Available";
              else if (tokenStateInteger == TOKEN_RESERVED)
                   return "Reserved";
              return "Unknown";
         * Parameterized constructor for a token.
         * Can be used to initialize a token with the following parameters
         * @param tokenID: Unique ID representing the Token
         * @param state: The state for the token, by default available
         * @param neID: The network ID this token associates to
         public Token(String tokenID, int state, String neID) {
              this.state = state;
              this.tokenID = tokenID;
              this.neID = "" + neID;
         // ----- PortableObject interface ---------------------------------------
         * The readExternal method is required for the implementation of the POF portableObject.
         * This method is used for serialization purposes
         * {@inheritDoc}
         public void readExternal(PofReader reader) throws IOException {
              tokenID = reader.readString(TOKENID);
              state = Integer.parseInt(reader.readString(STATE));
              neID = reader.readString(NEID);
         * The writeExternal method is required for the implementation of the POF portableObject.
         * This method is used for de-serialization purposes
         * {@inheritDoc}
         public void writeExternal(PofWriter writer) throws IOException {
              writer.writeString(TOKENID, tokenID);
              writer.writeString(STATE, Integer.toString(state));
              writer.writeString(NEID, neID);
    Edited by: 807103 on Oct 27, 2011 8:55 AM
    Edited by: 807103 on Oct 27, 2011 9:00 AM

  • Jar files are not exported while PAR Export

    Hi Experts,
    When  I am exporting as PAR file, in the par file  I am not getting the jar files, which I am adding as external jar files in the java build path - Libraries
    Please tell me the solution. urgent...
    Regards,
    Shyam

    Step 6 makes your third party jars available during runtime on your server since you put the dependency to runtime. I don't think you need/can reference your j2ee server dc in the portalapp.xml.
    Summary of the link I sent you:
    1. Create an External Library DC
    2. Copy all of the Jars I needed to the libraries folder of this DC
    3. Create two Public Parts (right click on the jar files in Package Explorer)
          i) compilePart (with purpose compilation)
          ii) assemblyPart (with purpose assembly)
    4 Create a new DC of type J2EE Server Component / Library
    5. Add a Used DC to the J2EE Library, reference the compilePart from previous step, and set Dependency type to Build
    6. Add another Used DC, reference the assemblePart, this time select both Build and Runtime Dependency Types
    7. Build and deploy.
    Br
    Göran

  • Launching a JAR file

    I am distributing my java application as a JAR file. The target OS is Windows. Before launching the application each time, I need to set some system variables. For this purpose I am using a batch file.
    When the application is launched, two windows open.
    1.Main application window
    2. Console window.
    I want to hide the Console window. How can I do this?

    But I want to launch a jar file directly instead of
    using the batch fileUse javaw.exe
    and also to set some system
    variables before launching it.Use a batch.

Maybe you are looking for

  • Mini SAP 7.01 under Windows Vista

    Hi every one, I wanna share my experience with you for installing version 7.01 under Vista. This might help you. I have installed the newest version ([Message from Klaus Keller| of Mini SAP under Windows Vista and, believe it or not, it all went corr

  • Error setting pretrigger samples

    I am having problems acquiring data with pretrigger samples when capturing more than one channel. If I trigger and capture on the same channel (tried 1-4) then it works great, regardless of the number of pre-trigger samples set. If I trigger on chann

  • Queries related to SQl Server

     I have one hosted Database Server on which using  SQL 2008 Web Edition  now We want to change to  SQL Standard edition # Server Config Dual Socket  Server populated  with  2 8 Core Processor # we use this Database server for our ecommerce Website .

  • WS-C2955T-12 DC power issue

    Can we operate the said switch on 48V DC power. Because on the switch tag it is mentioned as 24V

  • Is there any tutorial for using ARM cortex-A processors of Zynq for digital signal processing ?

    Hello, everyone. Is there any tutorial for using ARM cortex-A processors(such as A9 and A53) of Zynq to deal with digital signal processing  problems? Please tell me , thanks.