Including other JARs when packaging

Hello,
I have read the SUN tutorial on how to package my application, which I was able to do and execute fine. The problem is, in my application I use several database connection jar files, such as mysql-connector-java-5.0.4-bin.jar (MySQL) and jt400.jar (AS/400). When I try to do something in my application that uses one of these jar files, such as when I try to log in (uses a MySQL connection), I receive the following error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
My application works fine if its not packaged, but when it is, I receive this error. I tried putting the jar files in the package folder, but that did not help. I tried setting my classpath to those files in the package folder, that as well did nothing.
Could anyone help, or point me in the right direction?
Thank you.

But... it still requires me to extract the lib folder
out of the jar, and keep it in the same directory as
my main jar for it to read. I just want to be able
to double click on it and have it launch, without
needing to extract anything..That's the idea. You don't need to extract anything if you distribute your entire directory rather than trying to pack those other JAR files into your JAR file. The idea is that they're separate and your JAR file is linked to them. With your command
jar ... lib/*.jar
You're actually adding the JAR files to yours, rather than leaving them outside of it and just bundling everything up and distributing it. There's good reason to leave those JAR files separate. For example, when your MySQL driver gets updated you can distribute that single JAR file as an update (and perhaps your own if your code changed) rather than having to bundle everything up again and distribute the entire thing.

Similar Messages

  • How to include other jars when using servicegen

    I have been trying to use servicegen with regular java classes but I can't figure
    out how to include other jars that the webservice class uses?
    How is this supposed to be done?

    SQL> set null <<NULL>>
    SQL> select distinct comm from emp
      2  /
        COMM
           0
         300
         500
        1400
    <<NULL>>
    5 rijen zijn geselecteerd.So I probably don't understand the question. Could you post a small test case showing the behaviour you described?
    Regards,
    Rob.

  • How to include others jar in my project use netbean

    Hi,
    Here i'm build my project in netbean, in compile source i add jdom.jar. Afer compile, run jar from terminal. But, application can't use and error :
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jpos/
    iso/ISOPackager
    Now, i ask : How to include others lib or jar in my project use netbean
    Rgds,
    Wira S

    Dear All,
    The code In manifest.mf, like :
    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    Main-Class: root/Phase3/TesterPhase3/IsolibTester/src/isolibtester/DynamicTreeTester
    Class-Path: root/Phase3/TesterPhase3/jpos/lib/jdom.jar
    When build jar, error :
    error while reading original manifest: error in opening zip file
    Building jar: /root/PHASE3/TesterPhase3/IsolibTester/dist/IsolibTester.jar
    Manifest is invalid: Manifest sections should start with a "Name" attribute and not "Main-Class"
    /root/PHASE3/TesterPhase3/IsolibTester/nbproject/build-impl.xml:273: Invalid Manifest: /root/PHASE3/TesterPhase3/IsolibTester/manifest.mf
    BUILD FAILED (total time: 0 seconds)
    So, i tried add classpath in bash_profile and build.xml, unseccessful
    But, when runing my project from terminal can't found component jdom.jar

  • How to Include libraries (Jar's/Packages/ClassNotFoundException/Classpath)

    Ive spent hours looking for a solution, So maby i making a simple human error which i cant find.
    Im unfamiliar with using packages.
    I have created a program that use the JDBC libary. However i need to distribute this program and keep getting a ClassNotFoundException which is throw by:
    String s = "com.mysql.jdbc.Driver";
    Class.forName(s);I would like to have the "mysql-connector-java-bin.jar" file inside my main jar file However I think this may be very complex so i assume it would be easier to have it in the same directory as the main jar file.
    I create my main jar file with:
    jar cmf mainClass.txt Main.jar *.class mysql-connector-java-bin.jarI also jarsigner but i wouldn't expect this to case this problem.
    mainClass.txt
    Main-Class: MyClassFile
    Class-Path: mysql-connector-java-bin.jar
    Sealed: trueAny ideas what im doing wrong? or How i could solve this problem?
    Do i need to write a program which installs the JDBC on their system?
    Is there an easy solution?
    Any advice would be greatly appriacted.
    Thanks,

    ty for the reply
    I now create my jar file with:
    jar cmf mainClass.txt Main.jar *.classand the "mysql-connector-java-bin.jar" is still in same directory as my main.jar file
    Ive also replaced the "mysql-connector-java-bin.jar" to make sure it hasnt been corrupted somehow.
    However i still get the same error.
    the stackTrace is:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at SQLConnection.<init>(SQLConnection.java:18)SQLConnection a class i have created.and the lines 17 and 18 are posted in my first post.
    Anyideas?

  • Including utility jar when packing ejb in weblogic

    Hi,
    I am new to j2ee programming. I have an ejb which uses some utility jars. I followed the bea documents to structure the directory. The directory structure is, like,
    EjbProject
    - classes
    --com
    ---mine
    ----projectTracking --> has the class files of the ejb and supporting java files
    - src
    --com
    ---mine
    ----projectTracking --> contains the source files of the ejb and the supporting java files
    META-INF > contains ejb-jar.xml and weblogic-ejb-jar.xml
    The source java files are dependent on an utility jar file.
    so when I try the java weblogic.appc src, it throws me exception saying the utility file is missing. My question , is where should I put this utility jar file. Please send me your thoughts.
    Thanks in advance

    Hi,
    you can put your utility jar in the ear file along with the EJBs and make a classpath entry to these files in the EJB jar's META-INF\Manifest.mf file. As you said if you are working with weblogic you can put these files any where in the directory structure and place the entry in the startWeblogic.cmd file. But i recomend first option.
    Ashok.

  • [svn:bz-3.x] 5267: Update 3.x branch to include browserServer. jar in the packaged qa sdk zip.

    Revision: 5267
    Author: [email protected]
    Date: 2009-03-12 11:17:14 -0700 (Thu, 12 Mar 2009)
    Log Message:
    Update 3.x branch to include browserServer.jar in the packaged qa sdk zip.
    Modified Paths:
    blazeds/branches/3.x/qa/apps/qa-regress/build.xml

    I've been playing with this too.
    What kills it for me is my inability to get intelfb running properly on my eee 900 (says the module is loaded but there is no /dev/fb/0 device). One suggestion is to use a vga= code instead of video=intelfb:[etc] in my /boot/grub/menu.lst . But that makes it impossible to have the 1024x600 resolution of the eee's screen, so I haven't even tried it.
    Why intelfb? Because mplayer's directfb driver has tearing even with buffermode=triple and mplayer's -double tag enabled when using uvesafb. Maybe I am assuming too much that the intelfb would have the hardware acceleration hooks necessary to make it work?
    The other thing that cripples it for me is the "stuck at 16 colors" nature of Linux console even when running a framebuffer with a 32-bit background. I've gotten a tip on changing those colors but it is obtuse at best. Very surprised that there hasn't been a 256 color (at least) framebuffer console developed yet. (Unless screen magically enables the extra colors?) dfbterm looks interesting but the last thing I want is windowed terminals when I am trying to use CLI.
    Last edited by jceasless (2009-06-03 18:54:51)

  • How to include another .jar package in an applet jar package

    Hi, I'm using Eclipse to write an applet which needs some other .jar packages to support it. I add them as external jar package in project properties. In eclipse, everything works fine when I compile and run. But I when export the applet to .jar and try to run in browser, it doesnt work.
    I think probably because I didnt export the packages that the applet requires to run. However I cant find a way to export these packages together with the applet to a final .jar file.
    Anyone knows how to solve this ? plz help. thx you in advance

    Hi, I'm using Eclipse to write an applet which needs
    some other .jar packages to support it. I add them as
    external jar package in project properties. In
    eclipse, everything works fine when I compile and
    run. But I when export the applet to .jar and try to
    run in browser, it doesn't work.
    I think probably because I didn't export the packages
    that the applet requires to run. However I cant find
    a way to export these packages together with the
    applet to a final .jar file.
    Anyone knows how to solve this ? plz help. thx you in
    advanceHi all,
    I have been having the same problems too but came to realize that it is quite difficult getting your applet to work in most cases when using external jars. I found out thet you will have to create the directory hierarchy with the necessary imported classes used by your applet. and then create a new jar file that you will use in the codebase tag.
    For example:
    /* Java code snippet */
    import org.apache.XmlRpcClient;
    public MyApplet extends JApplet {
    //..... Rest of your code ......
    }/* End of snippet */
    You would then have to create a the directory structure:
    org
    _apache
    ___xmlrpc
    Then place all the required classes imported from within (Sometimes it is easier to just add all the classes to save time but lose space i.e. larger jar files).
    Execute the jar command (please adjust as needed to your requirements):
    jar cvf any_name.jar *.class org/
    After signing the applet it may solve your problem. Since I'm working with XmlRpc I still have a lot of problems. If anyone has any advice or tips, please share.
    Thank you

  • When Other Realtek Driver Packages Fail...

    There have been a number of posts, where problems with APE have been solved
    by reloading the REALTEK audio interface drivers.
    When Other Realtek Driver Packages Fail...
    try this one:
    AUD_ALLOS_XP_VISTA_5377_PV_REALTEK.EXE
    from:
    http://downloadcenter.intel.com/download.aspx?url=/11597/eng/UAA.zip&DwnldId=11597&lang=en g
    This is actually a composite of a number of fixes and updates from both
    Realtek and Microsoft. It is especially useful when other driver packages,
    including the current High Definition Driver package from Realtek's site,
    fail to load properly.
    Errors addressed include red and yellow error flags on the high definition
    audio driver entry in XP's device manager, and a PCI device that won't load
    a driver because an appropriate driver can't seem to be found.
    I ran into these problems when trying to upgrade an existing
    fully-configured XP system to a new motherboard. The audio driver provided
    by the motherboard vendor wouldn't load, and neither would the
    latest-greatest one from Realtek's site.
    As always, if your system is working OK right now, don't try to fix it!

    Though not specific to Realtek chips, there is also a little add-on, that has saved a lot of people with all flavors or Premiere, Audition and SounBooth - the freeware ASIO4All. This applet installs and sets up an ASIO environment that by-passes some of the problem areas encountered when trying to set up Audio with just the chip/card's driver. Once installed, it will appear in the ASIO settings list, or drop-down, depending on program. One has to point to it for all ASIO interfaces. Do not forget any other programs with Audio, such as Audacity, Magix Music Studio, etc.
    Hunt

  • How to access ejb jar in ear package from other war web package?

    How to access ejb in jar packed in ear package from other war web package?

    Typically you would just look the EJB Home up in JNDI. If you're
    looking for example code, the medrec example in WLS 8.1 or petstore has
    plenty of webapps calling EJBs.
    -- Rob
    CottonXu wrote:
    How to access ejb in jar packed in ear package from other war web package?

  • How to package other jar files into one jar?

    How to package other jar files into one jar? How can i get the class in the inner jar file?

    Generally not a good idea. The Java runtime won't be able to load classes from those "inner" jars, you'd have to write your own classloader to do that. It's not a brilliant idea, generally, anyway, since the point of having lots of jars is to keep your application modular. Bundling them all together like that means you have to re-deploy the whole thing to fix, for instance, one small bug in one small library
    If you really want to do this, there's an Eclipse plugin called FatJar, but I urge you to consider whether you really want to do it first.

  • Include many jars for a complex signed applet in html file??

    hello
    I'd like to know how it's possible to put a signed applet in an html file, that needs many jar files.
    I explain myself: I know that to create a signed applet and to put it in an html file, I need to create a Jar file that contains this applet, create a private key with keytool, sign the jar and include it in my html file with the tag <applet code="....." archive="......jar".... />
    This works fine if my applet is a simple program that only uses the clases present by default in the jdk.
    In my case, I have a big project, with many packages. In one of these packages, I have my applet that uses some classes of the other packages, which use classes from imported jars, such as BouncyCastle, and others...
    There is still no problem when I run the applet from the applet viewer.
    The problem appears when I put the JAR file with all these classes in the html file: there is a problem since it doesn't know anything of these classes imported from these jars.. It's quite obvious actually.
    My question is: how do I do to make the html file aware of these classes? Is there an html tag that allows us to include many jar files? Do I have to decompress all these jars, take all the directories, add them to the directories of my project and create a BIG jar (that's what I did, but it's really dirty, and heavy! (11M))??
    Does anyone have an idea about how I can do it?
    Thanks for your help
    Philippe

    11 MB is pretty big for an applet.
    Let's say your applet uses java 3d, normally a client would download and
    install this seporately, meaning the jars needed end up in lib/ext directory where
    any applet can find them.
    Check what applets need to be installed (put in lib/ext) and what can be
    downloaded:
    <object .....
    <param name="archive" value="myJar.jar, myOtherjar.jar" />

  • ANT - Jar File include another Jar file and importing classes

    Here is the directory structure i have set up:
    FTPGetter
      \src
        \com
          \abc
            \ftpgetter
              - GUI.java
              - FTPGetter.java
              - Login.java
      \classes
      \include
        - ftpClient.jar
        - info.xml
      \jar
        - FTPGetter.jarThe code compiles file and can create a Jar file without errors. But when I execute the Jar file, I get
    java.lang.NoClassDefFoundError: com/abc/ftpclient/FTPwhich is a class that I import from the ftpClient.jar file in FTPGetter.java
    What gives?
    Here is my necessary build.xml code:
    <?xml version="1.0"?>
    <project name="FTPGetter" default="all">
      <property name="src.dir"        value="src"/>
      <property name="package.name"   value="com.abc.ftpgetter"/>
      <property name="package.dir"    value="${src.dir}/com/abc/ftpgetter"/>
      <property name="classes.dir"    value="classes"/>
      <property name="include.dir"    value="include"/>
      <property name="jar.dir"        value="jar"/>
      <property name="javadoc.dir"    value="docs"/>
      <property name="javadoc.title"  value="FTPGetter"/>
      <property name="javadoc.header" value="FTPGetter - By ABC XYZ [2005]"/>
      <property name="run.classname"  value="${package.name}.FTPGetter"/>
      <target name="init">
        <mkdir dir="${javadoc.dir}" />
        <mkdir dir="${classes.dir}" />
        <mkdir dir="${jar.dir}" />
      </target>
      <target name="all" depends ="compile,jar" />
      <target name="compile" description="Compile Java code" depends="clean, init">
        <javac srcdir="${package.dir}" destdir="${classes.dir}">
          <classpath>
            <!-- use the value of the ${classes.dir} property in the classpath -->
            <pathelement path="${classes.dir}" />
            <!-- include all jar files  -->
            <fileset dir="${include.dir}">
              <include name="**/*.jar"/>
            </fileset>
          </classpath>
        </javac>
      </target>
      <target name="clean" description="Clean up">
        <delete dir="${javadoc.dir}" />
        <delete dir="${classes.dir}" />
        <delete dir="${jar.dir}" />
      </target>
      <target name="jar" depends="compile">
        <jar jarfile="${jar.dir}/FTPGetter.jar" update="false">
          <fileset dir="${classes.dir}" includes="**/*.class" />
    <!-- Include xml file to read.-->
          <fileset dir="${include.dir}" includes="info.xml" />
    <!-- Include ftpClient in the jar file.-->
          <fileset dir="${include.dir}" includes="ftpClient.jar" />
          <manifest>
            <attribute name="Main-Class" value="com.abc.ftpgetter.FTPGetter" />
            <attribute name="Class-Path" value="include/ftpClient.jar"/>
          </manifest>
        </jar>
      </target>
    </project>

    nevermind I got that fixed now:
    had to get the build.xml code for the <target name="jar" depends="compile">so that it looks more like:
      <target name="jar" depends="compile">
        <jar jarfile="${jar.dir}/FTPGetter.jar">
          <zipfileset dir="classes" prefix="" />
          <zipfileset src="include/ftpClient.jar" />
          <zipfileset dir="${include.dir}" includes="info.xml" />
          <manifest>
            <attribute name="Main-Class" value="com.abc.ftpgetter.FTPGetter" />
          </manifest>
        </jar>
      </target>Keyword would need to be zipfileset.

  • Big ANE causes java.lang.OutOfMemoryError when packaging Air application

    Hi,
    I'm working on an Air mobile game that uses ANE on iOS and Android. I'm in the process of creating a new ANE and face a problem on the Android side.
    My ANE requires an external framework (Burstly, http://burstly.com). If I just link the Android project to Burstly's .jar file, I get errors in "adb logcat", like:
    I/dalvikvm(16074): Could not find method com.burstly.lib.BurstlySdk.init, referenced from method com.freshplanet.burstly.functions.InitBurstlyFunction.call
    In order to include Burstly's files in my own .jar, I unzip Burstly's .jar file and repackage them with my compiled code in a unique .jar (following advice on http://stackoverflow.com/questions/7732742/air-3-native-extensions-for-android-can-i-how-t o-include-3rd-party-libraries).
    Problem: Burstly's SDK includes thousands of files. It doesn't create any trouble when packaging the ANE, but when I try to package the Air application, I get the following error:
    dx tool failed:
    UNEXPECTED TOP-LEVEL ERROR:
    java.lang.OutOfMemoryError: Java heap space
              at com.android.dx.util.IntList.<init>(IntList.java:87)
              at com.android.dx.rop.code.RopMethod.calcPredecessors(RopMethod.java:174)
              at com.android.dx.rop.code.RopMethod.labelToPredecessors(RopMethod.java:95)
              at com.android.dx.ssa.back.IdenticalBlockCombiner.process(IdenticalBlockCombiner.java:74)
              at com.android.dx.ssa.back.SsaToRop.convert(SsaToRop.java:132)
              at com.android.dx.ssa.back.SsaToRop.convertToRopMethod(SsaToRop.java:76)
              at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:103)
              at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:74)
              at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:269)
              at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131)
              at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85)
              at com.android.dx.command.dexer.Main.processClass(Main.java:299)
              at com.android.dx.command.dexer.Main.processFileBytes(Main.java:278)
              at com.android.dx.command.dexer.Main.access$100(Main.java:56)
              at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:229)
              at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
              at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
              at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
              at com.android.dx.command.dexer.Main.processOne(Main.java:247)
              at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
              at com.android.dx.command.dexer.Main.run(Main.java:139)
              at com.android.dx.command.dexer.Main.main(Main.java:120)
              at com.android.dx.command.Main.main(Main.java:89)
    I read that the solution to eliminate this error is to give Java the parameters "-Xms...M -Xmx...M", with "..." being a high-enough number. Note that I'm working on a machine with 8GB of RAM. I tried to package the app in command line to be able to pass these parameters:
    /usr/bin/java -Xms512M -Xmx4096M -jar "/Applications/Adobe Flash Builder 4.6/sdks/4.6.0air31/lib/adt.jar" -package -target apk -storetype pkcs12 -keystore [...].p12 Main.apk Main-app.xml Main.swf -extdir "/Users/alex/Documents/Adobe Flash Builder 4.6/.metadata/.plugins/com.adobe.flexbuilder.project.ui/ANEFiles/front-end-mobile/com.ado be.flexide.multiplatform.ios.platform"
    But when I run a "ps -ef | grep java", I can see that adt runs another Java program (dx) without transmitting my -Xms -Xmx parameters:
    /usr/bin/java -jar /Applications/Adobe Flash Builder 4.6/sdks/4.6.0air31/lib/android/bin/dx.jar --dex --output=/private/var/folders/t9/3kw74cx14nv2xg9tgmx9m1jc0000gp/T/b5757d93-1e93-439c-8f6d -c93e4933f6f1/outputDEX.dex [... bunch of jars]
    Any idea to solve this issue?
    Thanks
    Alex

    I solved my issue by setting the _JAVA_OPTIONS environment variable. (Note: there are two underscores)
    I added the following line to my .bash_profile:
    export _JAVA_OPTIONS="-Xms1024m -Xmx4096m -XX:MaxPermSize=512m"
    Now everytime a Java program is launched from the command line, I see the following message:
    Picked up _JAVA_OPTIONS: -Xms1024m -Xmx4096m -XX:MaxPermSize=512m
    And my application packaging runs just fine now.
    I still have an issue though: this trick solved the problem for packaging the app from the command line, but the _JAVA_OPTIONS are not picked up when packaging from Flash Builder, so it still crashes there.
    Note that my Adobe Flash Builder 4.6.ini contains the following options:
    -Xms512m
    -Xmx1676m
    -XX:MaxPermSize=512m
    -XX:PermSize=64m
    1676m is the highest number I can put before Flash Builder refuses to launch. I'm not sure if these parameters are actually passed to the VM that runs de dx.jar program, or if it's just for the ActionScript compiler. But anyway my app packaging still crashes in Flash Builder.
    If someone knows a way to force Flash Builder to pickup the _JAVA_OPTIONS set in the command line, let me know :-)
    Thanks
    Alex

  • How to combine Jars or Include dependent Jars into One Jar

    Hello,
    I have build a small utility using few libraries now i want to make a bundle or jar of this utility. I don't want to let use includes the jars individuals. I want to make a single jar using all the jars so user needs to include only one jar.
    So i need to include the dependent Jar files into a single jar.
    I got few solutions using Google.
    Like:
    adding a Class-Path: myjar.jar to MANIFESTfile.
    simply update the jar with jar using commnad jar uf main.jar myjar.jar_
    but these are not working. when i use the Class-Path option the Tree of main jar looks like
    main.jar
        <default-package>
             myjar.jar
        META-INF
             MANIFEST.MF
    How can i combine the Jars into a single Jar? Please help.

    It is to tell the JVM where to look for additional classesDoes it mean if i includes dependent jars to main jar and if i specify the path then JVM find that jars to specified pathThat's what 'telling the JVM where to look for additional classes' means, isn't it? I don't know what else it would mean.
    and don't need to include it separately?You only have to specify the Class-path in the manifest, and run the JAR file with java -jar. In fact if you specify a classpath on the command line with java -jar it will be ignored.
    All this is in the documentation.

  • How to include external jars - URGENT...

    Hi:
    I am using Eclipse for development.
    My application uses some external jars.
    This step is simple in Eclipse, one simply indicates where the jars are to the IDE.
    However, when I make an executable JAR file from my project, those external JARs are not included.
    So when I run my program, everything is fine until the parts that uses the external JARs.
    Does anyone know how to include them outside of Eclipse platform?
    I am going to see my client in an hour and of course I can't bring my source and install an Eclipse at my client's computer to show them my demo...
    please help... thanx...

    You add those external jars to the classpath or the jars classpath if you're running the program from a jar. Or put the external jar to JAVA_HOME\lib\ext (IIRC)

Maybe you are looking for