Packaging jar files

what is the recommeded packaging of jar files
i.e.
-by api
-by functionality
-by package
-by subpackage

Jar files are always packaged by the package structure.
The jar files must have classes in directory structure which matches the their respective package declaration.
ex. if you have a file called Hello.java with the package com.test.myapp
the the jar file must have this file in the following directory structure
com/test/myapp/Hello.class
Otherwise, the class loader will not be able to load your classes.
regards,
Abhishek.

Similar Messages

  • How to use a packaged Jar File?

    Greetings to everyone reading this post!
    I have a query about a thing that seems to be basic but I don't know how to accomplish, here it goes:
    I have packaged a Simple application into a Jar file. this application contains a package like this:
    lib.demo, inside this package I have a Class named MyClass with some simple methods like this one:
    public void sayHi(String name){
    //implementation here
    }Now, I would like to Know how to use the Method sayHI(String name) from an entirely different Project. I have successfully included the Jar File as a Library(in the new Project), but I have I no Clue on How to invoke a Class inside my Jar library, and more Importantly, a method.
    Could anybody help me?

    if the "project" (not a Java-related system, it's IDE-specific) already includes the JAR file in its classpath (library), then all you need is to import the package/class and invoke the method, as such:
    // in your client code:
    import lib.demo.*;         // or, import lib.demo.MyClass;
    public class Test {
      public void inAMethod() {
        MyClass myC = new MyClass();
        myC.sayHi("say hi"); 
    }simple.

  • Package jar files with the jdeveloper extension

    I have some dependent 3rd party jar files that needs to go with the extension. How can I package it with the extension?

    DJ,
    If you're still using 11.1.1.5 (or any version of 11gR1) place the third party libraries into a directory in your project, and reference them via the classpath entry in the extension.xml file.
    If you are looking at how you can distribute them with your extension, but not put them inside the extensions .jar file, then put them read this blog post about how to bundle your extension for distribution.
    http://blogs.oracle.com/jdevextensions/entry/working_with_jdeveloper_update_centers_and_bundlexml
    If you are adding external libraries to an extension in 11gR2, there is a blog post about that:
    http://blogs.oracle.com/jdevextensions/entry/adding_exteneral_jars_to_an
    --jb                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Packaging  jar  file with classes

    Hi experts,
    I want to clarify a problem in relation with packaging .class files in jar file making
    it jar executable.I was able to achieve this when number of classes are limited and confined to only a single program.However recently i developed a software
    which is very much like SQL*Plus and retriee my company database using screen buffer management and i have handled almost all the issues.
    But so long to execute this program i am typing
    java <Program name>.It is using Oracle as backend.
    I tried to package Oracle driver files in jar using
    jar -cmf manifest.mf sqlpad.jar *.class Oracle\
    where Oracle directory contains all the class files in separate folders like
    Oracle\javax etc
    I get a jar file with hefty MBs size.It is executable too.But when i try to connect to
    database, i get message Oracle driver class is not found.
    In what way should i package it as jar file ?

    I wouldn't add the drivers to the JAR itself. Instead, I'd suggest one of the following:
    1.) Add classpath entries into your manifest file pointing to the drivers' JARs
    2.) Create a batch file for starting that contains a call to "java -classpath ..."
    3.) Add some way to your app to configure additional classpaths at runtime and use a URLClasssLoader (and a wrapper class for the driver for registering with the DriverManager) that loads the driver's class

  • Adding jar file in my gerareted jar file using netbean 4.0

    Hi,
    I write an application de process XML file using JDOM. I add the JDom package jar file to my project and everything work fine. But when I generate, my project jar file using netbean 4.0, my generated jar, is not working with the XML files anymore. Everything seems like it didn't include the JDOM jar file?
    Thanks for any help to fix the problem.

    I find that you can not use command-line such as java -classpath add classpath
    it can not work, I use netBeans4.0 i don't whether because of netbeans or java itself.
    you can add classpath in jar's Manifest.mf file
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.2
    Created-By: 1.5.0_01-b08 (Sun Microsystems Inc.)
    Main-Class: chat.Main
    // add this line
    Class-Path: dir\*.jar //(jar file name)
    X-COMMENT: Main-Class will be added automatically by build

  • How to deploy a bunch of jar files

    All,
    I am just after downloading iPlanet App Server and have been trying to find information on how to deploy a bunch of packaged jar files.
    Basically if anyone can help it would be great, my problem is that I have a number of jar files that make up an application that I developed a while ago, I was using the 9ias app server but have decided to try out the iPlanet app server. Now what I need to know is how do I put the jar files onto the server for deployment???I had a look at the deployment tool but it would not allow me to deploy any of my jar files????Also a couple of the jar files I want to put into the class path, so where is that?
    Any help would be fantastic
    Thanks in advance
    J

    the first thing, that I suppose you know, is that iPlanet needs an extra xml file. If your jars have this exta xml file , the only thing is to use the iasdeploy command line to deploy your jars fles

  • ClassNotFoundException using Packages / JARs

    I have a program that I wrote that is essentially a remote desktop connection, except that it can control any number of computers that connect to the server program. It simply assumes each computer is setup exactly the same and only uses a screenshot feedback from one of the computers. The following files are involved, and all located in the same directory "RemoteControl"
    Directory: RemoteControl
    RCServer.java   - The server program
    RCClient.java   - The client program
    Resolution.java - Object containing information about the client's resolution
    ScreenShot.java - Object containing a Screenshot of the client's computer
    MyAction.java   - Object that dictates what action needs to be performedWhen the client connects to the server, the server writes a blank Resolution object to the client, which the client completes and sends back to the server. Outside of a package/JAR file, everything works just fine. However, when I add the line
    package RemoteControl;To each of the files above, compile them, and create 2 jar files like so:
    jar -cmf0 manifest.txt RCClient.jar RemoteControl
    jar -cmf0 manifest.txt RCServer.jar RemoteControlWith the manifest containing:
    Main-Class: RemoteControl/RCClientWith the blank line at the end (replace RCClient w/ RCServer when creating the server jar file), the server program starts up just fine, and so does the client portion. However, when the client actually connects to the server, and the server writes the Resolution object, I receive a "ClassNotFoundException". I extract all the files from the newly created JAR files (jar xf RCClient.jar/RCServer.jar) and they contain all the necessary files (and both JARs are identical with the exception of the manifest data).
    Looking at the stacktrace, the only line number it gives (rest are all Unknown Source/Native Method) points to the middle line in the following:
    System.out.println("starting thread loop - before reading object");
    Object tmp = in.readUnshared();
    System.out.println("object was read");And the console output stops at "starting thread loop - before reading object" before printing the stacktrace. Incase needed, in.readUnshared(); is an ObjectInputStream.
    My initial guess was something to do with resources in a JAR file, since in the past, I've had to use "getClass().getResource("images/gifIcon.gif");" to get an image within the JAR file to load during the application, however my research has told me all class files within the JAR are automatically loaded (assuming they are in the same directory at the main class), and that the Class-Path line in a manifest is only needed when you try to access classes within other JARs.
    Any ideas?
    Thanks in advance.
    Brad

    Here's the output from "jar -tf RCClient.jar"
    META-INF/
    META-INF/MANIFEST.MF
    RemoteControl/
    RemoteControl/BGPanel.class
    RemoteControl/Client.class
    RemoteControl/images/
    RemoteControl/images/gifIcon.gif
    RemoteControl/MyAction.class
    RemoteControl/MyAction.java
    RemoteControl/RCClient$1.class
    RemoteControl/RCClient.class
    RemoteControl/RCClient.java
    RemoteControl/RCServer.class
    RemoteControl/RCServer.java
    RemoteControl/RCServerGUI.class
    RemoteControl/Resolution.class
    RemoteControl/Resolution.java
    RemoteControl/ScreenShot.class
    RemoteControl/ScreenShot.java
    RemoteControl/ShowMessageListener.classAnd the output from "jar -tf RCServer.jar"
    META-INF/
    META-INF/MANIFEST.MF
    RemoteControl/
    RemoteControl/BGPanel.class
    RemoteControl/Client.class
    RemoteControl/images/
    RemoteControl/images/gifIcon.gif
    RemoteControl/MyAction.class
    RemoteControl/MyAction.java
    RemoteControl/RCClient$1.class
    RemoteControl/RCClient.class
    RemoteControl/RCClient.java
    RemoteControl/RCServer.class
    RemoteControl/RCServer.java
    RemoteControl/RCServerGUI.class
    RemoteControl/Resolution.class
    RemoteControl/Resolution.java
    RemoteControl/ScreenShot.class
    RemoteControl/ScreenShot.java
    RemoteControl/ShowMessageListener.classShortly after posting this question, I removed all the package declarations and deleted the class files and recompiled and I started getting the NoClassDefFoundError even though the .class file was in the same directory (not using a jar at this point), so I decided to revert back to earlier versions of the files above. When I compiled them and successfully ran them, I repeated the steps outlined in my OP and it started working, even within a JAR file. So, sadly I cannot provide a stacktrace anymore, but my problem's somehow solved.
    Note: The JARs that weren't working had the same output as above, which leads me to believe...
    Other than missing a few JOptionPane debugging prompts, the only possible difference I could think of is perhaps the Resolution object the server and client were using, were in different packages (or more specifically, one was in a package, one was not). Even though I did exactly the steps in my OP, I'm not going to rule out a possibility that somewhere, something wasn't over-written like it was supposed to (since I was compiling both the java files and the jars w/o deleting any previous .class/.jar files).
    And thanks for both the hasty reply, as well as informing me about the -tf option, that's a bit quicker than extracting the files and looking at the structure myself.

  • How to package an application as a JAR file?

    I want to package an executed JAR file,how to do?
    "jar cvf jar_name class_name"? But it can't run,:( help me.
    Thanks in advance.

    Suppose your main class call MyMainClass. You need to create a file called "mymanifest". In the mymanifest file, you need to include following line:
    Main-Class: MyMainClass
    Then you need to jar your jarfiles by:
    jar cvfm classes.jar mymanifest -C foo/ .
    After this, you can run your jar file by java -jar classes.jar.

  • Jar file is not working after deleting all packages from the same directory

    hello
    i have created a jar file named as server.jar in the same directory in which i have all the packages(for which i have created this jar file).This jar file was working correctly when i had all the packages in the same directory.But after deleting all the packages from the same working directory, this jar file is neither working nor giving any error message..
    Please tell me what may be the reason???
    thanks in advanced

    hello
    i have created a jar file named as server.jar in the same directory in which i have all the packages(for which i have created this jar file).This jar file was working correctly when i had all the packages in the same directory.But after deleting all the packages from the same working directory, this jar file is neither working nor giving any error message..
    Please tell me what may be the reason???
    thanks in advanced

  • Help! How to create Jar file for a packaged class?

    Hi!
    I am new in jar complexities. I made a swing frame that just prompts a JOptionPane when executed. I accomplished the same using jar without packaging my class SwingTest.
    But when i package it, it doesn't run. Can any one tell me how to make jar file of packaged classes and include images in the jar files too!
    Really Thanx!

    Call the Jar from the commandline to see the exceptions thrown.
    java -jar <jarFileName> <className>

  • How to create package and import from jar file?

    Hi all,
    I am writing a software and I am not sure how to create a package for the classes.
    Say I have two classes in the same directory as follows:
    testA.java
    ==========
    package AB;
    public class testA
    public static void main(String[] args){
         testB myB = new testB();
         System.out.println("A test");
    testB.java
    ===========
    package AB;
    public class testB
    public testB(){
         System.out.println("B constructor");
    both file compile without the package heading;
    both file compile using: javac -classpath .\ *.java
    Question 1:
    I cannot run testA by: java -classpath .\ testA
    I think it is a syntax error. What is the correct one?
    If I run testA by: java testA
    The only output I get is: A test
    But I am expecting: B constructor /n A test
    What went wrong?
    Question 2:
    I need to use APIs of another software. I have downloaded a .jar file (xxx.jar) with all the classes in it. And I have put "import xxx.*;" in my source file. But the compiler complains about the importing. What is the right way to copmile it?
    I have read a couple of tutorials but they don't answer my question.
    (I am using windows2000 and don't have the classpath variable.)
    Hope some one can help.
    Thanks a lot

    Try moving testA out of the package and importing 'AB.*;'
    If you have:
    ./testA.class
    ./AB/testb.class
    Then to execute testA from ./ type: java -cp . testA

  • How to load a xml file from a package inside of a jar file

    hi@all
    my application has got a xml configuration file which is saved inside the package tree of the class that reads this file.
    when i`m developing using eclipse the class can find that file, everything works fine. but when i create a jar file of my application to use it in another application it cannot find that file anymore.
    can anyone tell me how to solve this problem, please?
    thx a lot
    dialsc

    hi all,
    the xml file is in the jar file and
    ClassLoader.getSystemResourceAsStream(..) solved my problem.
    in fact i did nameOfClassInSamePackageAsXmlFile.class.getResourceAsStream("nameOfFile.xml");thank you all
    greez
    dialsc

  • Unable to access classes in third party jar files packaged with my ejb.jar

    I have packaged some third party jar files in my xxx_ejb.jar file.  The third party jar file contains classes that are accessed by some custom classes which are in turn accessed by my bean classes.  I get the following error when my custom classes attempt to use any of the classes in one of the third party jar files:
    java.lang.NoClassDefFoundError: com/Ostermiller/util/CSVParser
    Shouldn't I be able to access classes in jar files that are packaged with my xxx_ejb.jar file?  I see the xxx_ejb.jar file as a resource of the application classloader that contains it but I don't see the third party jar files.

    As per the Java EE specification, additional JAR files should be packaged on the EAR level. Only WAR files' WEB-INF/lib folder is scanned for JAR files to be added to the classloader.

  • Problem with JSP using bean packaged in jar file

    Hi,
              I am trying to use a java bean in a jsp file. The java bean is packaged
              into a jar file. I am getting class not found compilation error. If the
              bean remains to be a seperated class file, everything work well.
              Does anyone know how I can use bean in a jar file within jsp , i.e. to
              allow the bean to be found during compilation ?
              Thanks,
              Terence.
              [email protected]
              

    Jacek,
              Thanks for replying.
              My JSP's are just files in my document root . However, I found a solution to
              my
              problem. That is to have the jar file defined in my weblogic.class.path. I may
              have missed some files in my original jar file which causes my problem.
              Mayby I should package everything into a web application for deployment. That
              will be my next step.
              Thanks anyway.
              Terence.
              Jacek Laskowski wrote:
              > Terence Lai wrote:
              > >
              > > Hi,
              > >
              > > I am trying to use a java bean in a jsp file. The java bean is packaged
              > > into a jar file. I am getting class not found compilation error. If the
              > > bean remains to be a seperated class file, everything work well.
              >
              > How do you use the JSP file ? Is it a part of web application ? If so,
              > the bean jar package should be located in WEB-INF/lib directory. It's
              > also recommended to put the bean class into a package, so it's not in
              > 'unnamed' package, and <jsp:useBean> can find it.
              >
              > >
              > > Does anyone know how I can use bean in a jar file within jsp , i.e. to
              > > allow the bean to be found during compilation ?
              >
              > see above.
              >
              > > Terence.
              >
              > Jacek Laskowski
              > HP Consulting
              

  • How to use packages and jar files for applet?

    Hi!
    My applet takes a class say a.class.
    Now this class depends on other classes that are packaged
    in a directory and put separately.
    I want to put this applet on the web.
    So how do I manage the .class files in he package.
    I have tried using jar file format.But I was not able to get it working.
    Can someone please help me?
    Thanks

    Use Archive instead of codebase:
    <APPLET CODE="MyApplet.class" ARCHIVE="MyApplet.jar" WIDTH=400 HEIGHT=300></APPLET>

Maybe you are looking for

  • Three pretty basic questions--27" iMac, Snow Leopard

    New 27" iMac. Three (ridiculously basic) questions: 1) How do I take my old 24" iMac wireless keyboard and pair it with my new computer? I really despise this little keyboard that came with the current computer. 2) I default to Preview and Text Edit

  • Incorrect leaving date in ad hoc query

    Hi all Well I am running an ad hoc query for the numbers of leavers from the company and the reasons for it. This is working absolutely fine but its not showing the correct date of leaving for the employees. even if i have changed the period from 01.

  • Macbook Pro doesn't get CD/DVD inside the superdrive

    Hi every body! Last August I bought my first Mac, a Macbook Pro 15''. Less than two months after that, I have the next problem: when I want insert any CD/DVD on the SuperDrive, It doesn't accept it (it doesn't get the CD/DVD inside the Mac). But if I

  • Gradient Banding in CS3

    OK I've looked all over the internet, and have found no solution to this problem. I was using Illustrator CS3 and I noticed gradient banding in my project. It's not my monitor or color profile, I've checked on several computers. I checked in Photosho

  • Can't upload photos from iphoto 08

    now that I have upgraded to 08' when I click to upload a photo and go to my pictures folder, the iphoto library is grayed out where it is not a choice to click on. How do I fix this so I can upload pictures? thanks!