Including a DLL in JAR file (Comm API)

Writing a little app that interfaces with serial port device using the communications API and I'd like to bundle it into an executable JAR. JBuilder will create the JAR for me fine, but the issue is with the win32com.dll file thats part of the comms API. I need to include this, I don't think its possible to include as part of the executable, but otherwise the DLL needs to be in the windows\system folder. Could I include the dll as part of the JAR archive and then extract it upon runtime? If so how would I go about this?
Any help much appreciated.

There is another option. Native libraries need to reside within the java.library.path location. As it turns out, if you, at runtime, grab this property and ADD your own location to it, then set it back in to the System.setProperty() call, it will NOT work. The only way to do it is the -Djava.library.path value that tjmaven suggested.
However, if you read up on how a native library is found, it uses the ClassLoader.loadLibrary() which calls the protected findLibrary() method. You can therefore extend ClassLoader to find a path yourself.
One way is to extend URLClassLoader since it has the protection/security stuff AND the ability to look in .jar files for you. Your custom loader is created by a "launcher" class in your .jar file. First, your luancher uses getClass().getProtectionDomain().getCodeSource().getLocation() to get the absolute location of the .jar file its executing within. From there, you open the jar and look for your native library, extract it using the JAR api to a location of your choosing. Now, you instantiate the custom classloader and using this custom loader instance you load the rest of your classes. The main .jar file contains two classes, the launcher and the custom classloader, and contains the native library if you wish to do it this way. The custom classloader, you specify a URL[] of "classpath" entries. You bundle up the rest of your source in a second .jar file that you pass to the URL[] when creating the custom classloader. It will find all your classes in the 2nd jar no sweat. You can even "reload" these classes on the fly by recreating the custom classloader instance if you so wish to add a sort of "reload" feature.
Now, in your custom classloader, you override the findLibrary() and return the SAME STRING PATH that you used to unjar your native files to. This way, when the JVM asks your custom loader to load the library at some path, you return the right path to find the native files in.
I haven't verified that this works just yet, but I will soon. Primarily, my plugin engine over at www.platonos.org will support the ability to place native libraries in plugins, allowing you to effectively wrap a native library use as a plugin. Not yet working, but we'll soon have it in place.

Similar Messages

  • Include an in-memory jar file for JSR-199 compilation

    I want to compile a source file in memory, which requires a jar file that is also represented in memory. I used the JavaSourceFromString class recommended in the documentation for the class JavaCompiler and in a demo I found online that shows how to compile sources represented as String in memory. To represent the jar file, I used a similar trick to JavaSourceFromString:
    public class JarJavaFileObjectFromByteArray extends SimpleJavaFileObject {
       * The contents of this jar file.
      private final byte[] contents;
       * Constructs a new JarJavaFileObjectFromByteArray given the name and binary
       * contents of a jar file.
       * @param name the name of this jar file
       * @param contents the contents of this jar file
      public JarJavaFileObjectFromByteArray(String name, byte[] contents) {
        super(newURI(name), Kind.OTHER);
        this.contents = contents;
      ... // code not shown ensures that the URI returned from newURI is of the form,
          // for instance, bytes:///MathConstants.jar, if the name of the jar file is MathConstants.jar
      @Override
      public InputStream openInputStream() throws IOException {
        return new ByteArrayInputStream(contents);
    }However, I do not know how to alert the compiler that this jar file should be on the classpath. I tried this:
    List<String> options = Arrays.asList(" -classpath bytes:///MathConstants.jar ");
    CompilationTask task = compiler.getTask(null, fileManager, null, options, null, compilationUnits);but I get the following error when calling getTask:
    java.lang.IllegalArgumentException: invalid flag: -classpath bytes:///MathConstants.jarI assume there is some way to tell the compiler, "look at the MathConstants.jar file that I am storing in memory when searching the classpath", but I do not know how to do this. I assumed that the options parameter for getTask represents command-line flags that would be passed to the compiler if this were happening on the command line (such as "-cp .", which also does not work), but perhaps this assumption is wrong.

    Hi Bruce,
    I have a question regarding loading a jar file by the compiler to dynamically compile with a source file. I hope you can probably offer me an idea on what has been missing or wrong with the source codes I have written for my application.
    I am using Eclipse compiler to dynamically compile a class. In the class, I want it to make a reference to a jar file for compilation dynamically.
    Here is the source of a test class I wrote:
    import javax.servlet.http.HttpServlet;
    class MyServlet extends HttpServlet {
    }The import statement refers to the class javax.servlet.http.HttpServlet from the jar file C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\lib\\servlet-api.jar placed in the file system.
    In the method called compileClass (shown below), I used the path of the jar file to add to the option -classpath as you suggested.
         private static CompileClassResult compileClass(Writer out, String className, String classSource) {
              try {
                   JavaCompiler javac = new EclipseCompiler();
                   StandardJavaFileManager sjfm = javac.getStandardFileManager(null, null, null);
                   SpecialClassLoader scl = new SpecialClassLoader();
                   SpecialJavaFileManager fileManager = new SpecialJavaFileManager(sjfm, scl);
                   List<String> options = new ArrayList<String>();
                   options.addAll(Arrays.asList("-classpath", "C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\lib\\servlet-api.jar"));
                   List<MemorySource> compilationUnits = Arrays.asList(new MemorySource(className, classSource));
                   DiagnosticListener<JavaFileObject> diagnosticListener = null;
                   Iterable<String> classes = null;
                   if (out == null) {
                        out = new PrintWriter(System.err);
                   JavaCompiler.CompilationTask compile = javac.getTask(out, fileManager, diagnosticListener, options, classes, compilationUnits);
                   boolean res = compile.call();
                   if (res) {
                        //Need to modify the api to return an array of two elements - one classes and other bytecodes for all classes in the same class file.
                        return CompileClassResult.newInstance(scl.findClasses(), scl.findByteCodes());
              } catch (Exception e) {
                   e.printStackTrace();               
              return null;
         }I also extended the class ForwardingJavaFileManager as you suggested and have it delegated to the StandardJavaFileManager sent to the compiler mentioned in the method compileClass above. The extended class (called SpecialJavaFileManager) is as follows:
    public class SpecialJavaFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
         private SpecialClassLoader xcl;
         public SpecialJavaFileManager(StandardJavaFileManager sjfm, SpecialClassLoader xcl) {
              super(sjfm);
              System.out.println("SpecialJavaFileManager");
              this.xcl = xcl;
         public JavaFileObject getJavaFileForOutput(Location location, String name, JavaFileObject.Kind kind, FileObject sibling) throws IOException {
              System.out.println("getJavaFileForOutput");
              MemoryByteCode mbc = new MemoryByteCode(name);
              xcl.addClass(name, mbc);
              return mbc;
         public Iterable<JavaFileObject> list(JavaFileManager.Location loc, String pkg, Set kinds, boolean recurse) throws IOException {
              System.out.println("list ");
            List<JavaFileObject> result = new ArrayList<JavaFileObject>();
            for (JavaFileObject f : super.list(loc, pkg, kinds, recurse)) {
                 System.out.println(f);
                result.add(f);
              return result;
    }I run the application and the result shows that it didn't load the jar file into the memory as expected. From the output (below) I got, it doesn't seem to invoke the method list(...) in the class SpecialJavaFileManager.
    SpecialJavaFileManager
    1. ERROR in \MyServlet.java (at line 1)
         import javax.servlet.http.*;
                ^^^^^^^^^^^^^
    The import javax.servlet cannot be resolved
    2. ERROR in \MyServlet.java (at line 3)
         class MyServlet extends HttpServlet {
                                 ^^^^^^^^^^^
    HttpServlet cannot be resolved to a typeWould you please let me know what has possibly be missing or wrong?
    Thanks.
    Jonathan
    Edited by: jonathanlam on Aug 10, 2009 6:47 PM

  • How to include externel library in JAR file?

    Hi all =)
    I have a program that uses an external library (in a JAR file) I would like to compile my program as a JAR and have it include the external library that it needs to run, so that the external library would not need to be on the computer running my program. How can I do this?
    Thanks =)
    Koneko349
    Message was edited by:
    Koneko349

    Ok I was able to make my JAR and launch my application correctly. However whenever I click a button that has a method using my external library I get the following error:
    C:\Documents and Settings\Koneko>java -jar D:\Mangment.jar
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/POIFSFileSystem at managment_system.ManagmentGUI.getNextStat(ManagmentGUI.java:569) at managment_system.ManagmentGUI$1.actionPerformed(ManagmentGUI.java:195)
    I do not get this error when I run and use my program from within the IDE.
    The JAR that has my external library (and has the class for POIFileSystem) is also on my D drive and i referenced it correctly (I think) In my classpath:
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
         <classpathentry kind="src" path=""/>
         <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
         <classpathentry kind="lib" path="D:/poi.jar"/>
         <classpathentry kind="output" path=""/>
    </classpath>I would really like to get this working and I'm very confused XP

  • How to include grouplayout in my .jar file.

    Hello,
    I have a program that works great on my comptuer and the one in my lab. I would like to deploy this .jar file to other systems, but these other systems are only running JRE 1.5.0_10-b03. The problem, as I understand it, is that swing.grouplayout first appeared in JRE1.6.XX so these older versions don't have the proper librairies to run this.
    How do I include the grouplayout class with my .jar file. I have searched all over my HDD and cannot find the grouplayout class file to include. Am I on the right track?
    Thanks!
    -- Snow

    Note: This thread was originally posted in the [New To Java|http://forums.sun.com/forum.jspa?forumID=54] forum, but moved to this forum for closer topic alignment.

  • Including pictures in a jar file

    Hi all, I want to create a jar file where I include a couple of pictures...... I have succesfully included them into the archive but I have found that the coding I use cannot be sued within a .jar file and hence none of the pictures are loaded :( I'm using kit.getImage("imagename.gif") command to load the images..... this does howeevr not seem to work when using a .jar file....... anyone got anyideas of what code should go instead of the kit.getImage("imagename.gif") ?
    Thx
    Garaz

    I would reply to that but I'll just stick with what
    you gave me..... thx for replying anyway, at a first
    look it seems as if I didn't specify the search
    pattern anough to get a good score when seraching....
    well thx for replyingDon't take it personally, this question has just been answered many times lately. I didn't feel like doing it again.

  • How to Include more than one jar files

    My application uses more than one jar files. And all the jar files i am using are signed. when i include the jar files, i am including them in the resources section of the ".jnlp" file . The section of code looks like this:
    <resources>
    <jar href="utestfw.jar" main="true" download="eager"/>
    <jar href="crimson.jar"/>
    <jar href="jaxp.jar"/>
    </resources>
    <application-desc main-class="utestfw.ObjectBrowser"/>
    The deployment of the application is successful. The jar file - "utestfw.jar" contains the application main class when the application is launched it works, but when i choose the feature which involves the classes of either "crimson.jar" or "jaxp.jar" , the application terminates and the webstart console and the application is closed automatically. Am i wrong in adding the jar files? what is the way to add more than one jar files to the ".jnlp" file.
    Can anyone please help me?
    -Aparna

    I'll post u the jnlp file which i am using. To sign all the jars i've used the same alias ( a self signed certificate using keytool and jarsigner).Here is the jnlp file:
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="0.2 1.0"
    codebase="http://127.0.0.1:8080/healthdec"
    href="testTool.jnlp">
    <information>
    <title>Unit Test Manager </title>
    <vendor>Sun Microsystems, Inc.</vendor>
    <description>A minimalist drawing application along the lines of Illustrator</description>
    <icon href="images/testing.gif"/>
    <offline-allowed/>
    </information>
    <resources>
    <j2se version="1.3+ 1.2+"/>
    <jar href="utestfw.jar" main="true" download="eager"/>
    <jar href="crimson.jar" main="false" download="eager"/>
    <jar href="jaxp.jar" main="false" download="eager"/>
    </resources>
    <application-desc main-class="utestfw.ObjectBrowser"/>
    <security>
    <all-permissions/>
    </security>
    </jnlp>
    Can u please look at the above code and suggest me where i am wrong. Thanks.
    -Regards
    Aparna

  • Making jar files using API

    hello!
    I m trying to make a jar file using the API. When the jar tool is used for the same manifest file, it is correctly written and an executable jar is created. When I use the API, the jar file is made but it is nor executable. Here is that part of code:
    jar = new File(parent, jarName);
    System.out.println("Executing jar command...");
    //create jar file here
    Manifest mf = new Manifest(new FileInputStream(manifest));
    fos = new FileOutputStream(jar);
    jos = new JarOutputStream(new BufferedOutputStream(fos), mf);
    BufferedInputStream reader = null;
    byte[] data = new byte[BUFFER];
    int byteCount = 0;
    for(int i = 0; i < fileNames.length; i++)
    System.out.println("Adding " + fileNames);
    FileInputStream fis = new FileInputStream(fileNames);
    reader = new BufferedInputStream(fis, BUFFER);
    JarEntry entry = new JarEntry(new ZipEntry(fileNames));
    jos.putNextEntry(entry);
    while((byteCount = reader.read(data,0,BUFFER)) != -1)
    jos.write(data, 0, byteCount);
    }//end while
    reader.close();
    }//end for
    jos.close();//close jar output stream
    fos.close();
    I m sure someone will be kind and intelligent enough to solve the problem. Thank you!
    Umer

    A jar file is simply a Zip file. So the two API's are quite similar. First, you create a CRC - that is a way to make sure that the file isn't corrupted and that all the bytes are there (it's a polynominal algorithm that returns a number which is written in the Zip(Jar) file as well). Each entry is a file or directory. Before writing any data to the Zip(Jar) file, you have to write info on the actual file (like name, path, length etc). That's why you use putNextEntry(). Each file can have it's storing methods, although the most common is to use the "default" methods (built in the ZipOutputStream/JarOutputStream)
    But in this example you set the storing methods on the entry. You use the setMethod() method to switch between either storing or compression (don't know why, but in this example you don't compress the file - you should). I myself don't use the setSize() and setCompressedSize() methods at all (and it works fine). Don't know exactly what are the implications of using them. Neither do I use the setCrc() method (If I think a little, I've only used this API once - I don't use it that much), but it's quite straightforward. It's used to check that the data is ok, and since the CRC number is the result of an algorithm, it needs to know the bytes of UNCOMPRESSED data: that's why you use crc.update() on the bytes. After that you actually write all the info set before to the Zip (Jar) file using putNextEntry(). But remember that a ZipEntry doesn't have any data. You'll have to write it yourself: thus the need for the write method: Here are two small programs I used for Zipping and Unzipping. Changing them to work for Jar files is extremely simple:
    //Zip.java
    import java.io.*;
    import java.util.zip.*;
    public class Zip
         public static void main(String[] arg)
              try
                   if (arg.length < 3)
                        System.out.println("Usage: java Zip <0-9> <zip file> <file 1> [file 2] [file 3] ...");
                        System.exit(0);
                   System.out.println("Compressing files into file " + arg[1]);
                   ZipOutputStream out = null;
                   try
                        out = new ZipOutputStream(new FileOutputStream(arg[1]));
                   catch (FileNotFoundException ex)
                        System.out.println("Cannot create file " + arg[1]);
                        System.exit(1);
                   try
                        out.setLevel(Integer.parseInt(arg[0]));
                   catch (IllegalArgumentException ex)
                        System.out.println("Illegal compression level");
                        new File(arg[1]).delete();
                        System.exit(1);
                   for (int i=2; i<arg.length; i++)
                        System.out.println("\tCompressing file " + (i-1));
                        FileInputStream read = null;
                        try
                             read = new FileInputStream(arg);
                        catch (FileNotFoundException ex)
                             System.out.println("\tCannot find file " + arg[i]);
                             continue;
                        out.putNextEntry(new ZipEntry(arg[i]));
                        int av = 0;
                        while ((av = read.available()) != 0)
                             byte[] b = new byte[av < 64 ? av : 64];
                             read.read(b);
                             out.write(b);
                        out.closeEntry();
                        read.close();
                        System.out.println("\tDone compressing file " + i);
                   System.out.println("Done compressing");
                   out.finish();
                   out.close();
              catch (Exception e)
                   new File(arg[1]).delete();
                   e.printStackTrace(System.err);
    And the unzipping app:
    //UnZip.java
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    public class UnZip
         public static void main(String[] arg)
              try
                   if (arg.length < 1)
                        System.out.println("Usage: java UnZip <zip file> [to dir]");
                        System.exit(0);
                   String dir = "";
                   if (arg.length > 1)
                        dir = arg[1] + System.getProperty("file.separator");
                        File f = new File(arg[1]);
                        if (!f.exists()) f.mkdirs();
                   System.out.println("Decompressing files from file " + arg[0]);
                   ZipFile read = null;
                   try
                        read = new ZipFile(arg[0]);
                   catch (ZipException ex)
                        System.err.println("Zip error when reading file " + arg[0]);
                        System.exit(1);
                   catch (IOException ex)
                        System.err.println("I/O Exception when reading file " + arg[0]);
                        System.exit(1);
                   Enumeration en = read.entries();
                   while (en.hasMoreElements())
                        ZipEntry entry = (ZipEntry) en.nextElement();
                        System.out.println("\tDecompressing file " + entry.getName());
                        FileOutputStream out;
                        try
                             out = new FileOutputStream(dir + entry.getName());
                        catch (FileNotFoundException ex)
                             System.err.println("\tCannot write down to file " + dir + entry.getName());
                             continue;
                        InputStream re = read.getInputStream(entry);
                        int nRead = 0;
                        for (byte[] buffer = new byte[1024]; (nRead = re.read(buffer)) != -1; out.write(buffer, 0, nRead));
                        out.close();
                        System.out.println("\tDone decompressing file " + entry.getName());
                   read.close();
                   System.out.println("Done decompressing files");
              catch (Exception e)
                   new File(arg[1]).delete();
                   e.printStackTrace(System.err);

  • How to make the ear file including the 3rd party jar files without menttion in the System Classpath.

    Hai Sir,
    I am facing one problme in weblogic8.1 while depolying the .EAR FILE.
    Please help me sir.
    Case1)     1) I am using the struts and log4j frameworks and 3rd party jar files with
    weblogic8.1.
         2) I make the ejbs,webapplications and 3rdparty jar files, ear file the following
    dir structure .And i mentioned the Class-path including all jar files in the MANIFEST
    OF EAR FILE.
         While deploying the ear file it is giving following error.If log4j.jar does not
    mention in the Weblogic script file
         java.lang.NoClassDefFoundError: org/apache/log4j/Priority
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:1494)
    at java.lang.Class.getDeclaredFields(Class.java:1073)
    at weblogic.ejb20.deployer.EJBModule.disableImplClassLoader(EJBModule.java:1082)
    at weblogic.ejb20.deployer.EJBModule.setupEJBToImplClassDependencies(EJBModule.jav
    a:982)
    at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:419)
    at weblogic.j2ee.J2EEApplicationContainer.prepareModule(J2EEApplicationContainer.j
    ava:2792)
    at weblogic.j2ee.J2EEApplicationContainer.prepareModules(J2EEApplicationContainer.
    java:1478)
    at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:11
    36)
    at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:97
    5)
    at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.prepareCon
    tainer(SlaveDeployer.java:2571)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.createContainer(Sla
    veDeployer.java:2523)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeploy
    er.java:2453)
    at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer
    .java:820)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:
    536)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java
    :494)
    at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:
    25)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)
    Please provide the soluation without mentioning classpath in the weblogic script
    .How to make the EAR file incliding ejbjar,webapplication and 3rd party jar files.
    Thanks & Regards,
    ASHOK SAMRAT
    [email protected]

    Refer to the section
    Handling Utility classes
    http://dev2dev.bea.com/products/wlserver/articles/musser.jsp
    thanks,
    Deepak
    "Ashok Samrat" <[email protected]> wrote:
    >
    Hai Sir,
    I am facing one problme in weblogic8.1 while depolying the .EAR FILE.
    Please help me sir.
    Case1)     1) I am using the struts and log4j frameworks and 3rd party jar
    files with
    weblogic8.1.
         2) I make the ejbs,webapplications and 3rdparty jar files, ear file
    the following
    dir structure .And i mentioned the Class-path including all jar files
    in the MANIFEST
    OF EAR FILE.
         While deploying the ear file it is giving following error.If log4j.jar
    does not
    mention in the Weblogic script file
         java.lang.NoClassDefFoundError: org/apache/log4j/Priority
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:1494)
    at java.lang.Class.getDeclaredFields(Class.java:1073)
    at weblogic.ejb20.deployer.EJBModule.disableImplClassLoader(EJBModule.java:1082)
    at weblogic.ejb20.deployer.EJBModule.setupEJBToImplClassDependencies(EJBModule.jav
    a:982)
    at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:419)
    at weblogic.j2ee.J2EEApplicationContainer.prepareModule(J2EEApplicationContainer.j
    ava:2792)
    at weblogic.j2ee.J2EEApplicationContainer.prepareModules(J2EEApplicationContainer.
    java:1478)
    at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:11
    36)
    at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:97
    5)
    at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.prepareCon
    tainer(SlaveDeployer.java:2571)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.createContainer(Sla
    veDeployer.java:2523)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeploy
    er.java:2453)
    at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer
    .java:820)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:
    536)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java
    :494)
    at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:
    25)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)
    Please provide the soluation without mentioning classpath in the weblogic
    script
    How to make the EAR file incliding ejbjar,webapplication and 3rd party
    jar files.
    Thanks & Regards,
    ASHOK SAMRAT
    [email protected]

  • How to include images on a jar file with WSDD

    Hello there!
    I�m using WSDD 5.7 and I�ve created a build with the "Device Developer Builds" tool to generate a jar file. My project contains a package with images inside, the problem is that everytime I generate the jar file it does not contain that package. Any idea?
    cheers!

    I�m using WSDD 5.7 and I�ve created a build with the
    "Device Developer Builds" tool to generate a jar
    file. My project contains a package with images
    inside, the problem is that everytime I generate the
    jar file it does not contain that package. Any idea?I had the same problem and found a workaorund. See my thread in the WSDD forum for details:
    http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?message=13774631&cat=9&thread=102493&treeDisplayType=threadmode1&forum=277#13774631

  • During deployment include certain third party jars using deployment API.

    I am trying to deploy using the weblogic deployment API ( Weblogic 10.0) and want to include certain external jars during the deployment process. I have found that one way is to provide in the setWLSenv.bat but I cannot include the external jars that are runtime specific.
    In websphere we can pass the classess as a parameter (-cp) to the WAS Deploy tool (ejbdeploy) but need to find how to do it in Weblogic 10.0
    Edited by: user10643013 on Nov 23, 2008 10:40 AM

    IDE and Maven have nothing to do with it.
    You need to look at your Oracle AS docs and put the 3rd party JARs in the directory where it expects to find them. I don't know where that is. Most Java EE app servers are different. WebLogic uses an APP-INF directory at the top level of the EAR file. I don't believe it's a Java EE standard. There's more variability in EAR arrangements than there is for WAR files. Those are standard.
    %

  • Java application - build JAR file & include JCO library

    Hello everyone,
    I have a problem with my Java application that <i>connects to SAP system using JCO </i>library <b>(sapjco.jar)</b>.
    I would like to create a JAR file from my Java application but when I run the JAR file that I created I get an error that <b>NoClassDefinitionFoundError com/sap/mw/jco/JCO at [...]</b>
    That means that the JCO and associated DLL files <b>(sapjco.jar, librfc32.dll and sapjcorfc.dll)</b> were <u>not</u> included/packed in my JAR file.
    <b>-- How can I include the JCO lib in JAR file?
    -- If there is a problem with the DLL files, how can I include the JCO lib externally (dynamicly read the JCO whenever my JAR in run)?</b>
    I am using Eclipse 3.2 and Export to JAR option when I click right button on Project.
    THANKS IN ADVANCE FOR HELP!!!

    Hi,
    The problem is that you don't have defined the libraries in the Manifest file of your jar-file. So the jar doesn't know what to use at runtime.
    Add following entry to the MANIFEST.MF file:
    Class-Path:/<lib_folder>/<lib1_name>.jar; /<lib_folder>/<lib2_name>.jar and so on.
    Regards,
    Daniel

  • Including web service jaras in final jar file

    Hello all.
    Im using netbeans 4.0. I have used JAXB code in my program, ie. Ive used a few packages I created with the XJC compiler so i can unmarshall some XML documents. I have included the four JAXB Jar files from the Java Web Services Developer Pack in my project by including them in the projects "Classpath for compiling sources". This works fine when running in netbeans. But when I try running the project outside netbeans by double clicking on the generated JAR file I get a
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    Im guessing this is because it can't see the jaxb jar files when not run from within netbeans. How would I include the jaxb jars in the jar file that netbeans generates?
    I know this is partly an IDE related question but I thought it must be a fairly common problem when creating JAR files so i posted it here.
    Any help is appreciated.
    thanks

    Im guessing this is because it can't see the jaxb jar
    files when not run from within netbeans. How would I
    include the jaxb jars in the jar file that netbeans
    generates? You wouldn't include them in that jar file. You would include Class-Path entries (which refer to the jaxb jars) in the manifest of the jar file that Netbeans creates.
    Don't ask me how to do that, I don't use Netbeans. I assume that Netbeans must support it somehow, but if you can't find out how then a Netbeans forum would be a good place to ask.
    I know this is partly an IDE related question but I
    thought it must be a fairly common problem when
    creating JAR files so i posted it here.

  • JAR file including database connection

    Hello,
    I made an application ( GUI ) which uses a MS acces Database.
    I used Netbeans, so a JAR file is automatically created.
    The only problem is that when I run the Jar file ,the application isn't able to find the connection with the database.
    Very annoying, but I do not know how to include it in my JAR file.
    Is it possible? Maybe not, because access is from windows, while JAR is independent of the running platform.
    If not, is it possible to make it run independently in another way, for example 'exe-file'.
    If yes, how?Any ideas...
    I've been looking for a couple of weeks, but never found a satisfying solution...
    I just want to be able to run the application without the need of netbeans.
    Thanks in advance.

    Thx for your quick replies!
    First of all , I will give you more details how I made connection with access. Beneath you find my class 'Database".
    Then, I made an object from that class and use it for example createStatements:
    {code}Statement stmt = db.getDbConnection().createStatement();{code} (db = object from class Database )
    {code}package database;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class Database {
    private Connection dbConnection;
    public Database(String file) {
    loadDriver();
    connectDatabase(file);
    private void loadDriver() {
    try
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    catch (ClassNotFoundException err)
    System.out.println("Could not load driver ");
    System.exit(1);
    private void connectDatabase(String dbFile) {
    try
    String protocol ="jdbc";
    String subProtocol = "odbc";
    String subName ="Driver={Microsoft Access Driver (*.mdb)};DBQ= "+dbFile;
    String URL = protocol + ":" + subProtocol + ":" + subName;
         dbConnection = DriverManager.getConnection(URL);
    catch(SQLException error)
    System.err.println("Error connecting to database: " + error.toString());
    public void closeConnection() {
    try
    dbConnection.close();
    catch(SQLException error)
    System.err.println("Cannot disconnect database");
    public Connection getDbConnection(){
    return dbConnection;
    }{code}
    You said that the resources have to exist when you run it...Okay. In netbeans that's easy because it's part of java language and netbeans loads everything he needs... But how can I realise it to run without netbeans?
    Btw, it's no problem that the application is only runnable on windows. I was just wondering...
    If you need some more information, just ask. It's not always easy for me to understand what information a specialist like you needs ;-)

  • 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.

  • No media in JAR files ????????

    But what the heck were you thinking ?
    [http://javafx.com/docs/articles/porting-guide-javafx1-3.jsp]
    MP3
    MP3 files can no longer be loaded directly from .jar files. See JavaFX FAQ Section 5.3 for more information. [http://javafx.com/faq/#5.3]
    *5.3 Can I include media in my JAR file?*
    No. Distributing media in JAR files is not efficient and is therefore not supported at this time. However, explorations of this capability for small media files (such as short audio/video clips) might lead to this support in the future.
    Media files tend to be large, so you'll want to carefully consider how to distribute media content to your audience. You don't want users to wait for long periods of time while downloading files, for instance, which would certainly be the outcome for media packaged in the JAR. Also, as media files are already compressed, packaging them in additional compressed formats like .zip or .tar files can actually result in increasing the file size.
    You are strongly urged to leverage the streaming capability in JavaFX technology. Because JavaFX Media supports streaming audio/video, you can achieve very short download times (for just the application) and take advantage of the streaming capability to play media content. The streaming capability will result in much higher performance and improved usability of your applications.I think somehow you forgot to realize that the entire planet IS NOT connected 100% of time to fast speed internet and that we cannot afford to have our application stream media on the fly every time or on the first launch (and find a hack to store them locally).
    We've already having as much trouble as possible trying to figure out how to deploy/distribute a real desktop or pure-offline JavaFX app with the runtime distribution issue (of which nothing was fixed in 1.3) without additionnal "stay online all the time" burden.
    Additionnaly as this seems to only apply to the classes from the JavaFX API, it seems nothing prevents us from embedding the media in the JAR and using some Java+classpath code to extract them locally.
    So in the end it looks more like some legal mumbo-jumbo side-effects put in place to prevent the Java store from beeing sued because some people put illegal video and musics in their apps stored over there that the very idiotic published explaination which is basically just BS (sorry).

    +1
    Not allowing to embed resources (MP3 are resources like icons or images or text files) is stupid and handicapping, particularly for small sound effect files we use in games.
    Another step away from using JavaFX on (unconnected) desktop... :-(

Maybe you are looking for