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.

Similar Messages

  • Packaging JAR's using Ant in Eclipse

    Hey,
    I'm new to Ant, and xml for that matter. I need to rmi compile & package a set of simple classes whose objects call eachother remotely. I need seperate jars for a "server" and one for "client" containing whatever classes are needed for each. Using Ant the classes should be compiled, packaged into the jars and then the jars should be copied to some other specified directory. And of course, the jars should be executable.
    The files I use are AddressBook (interface extends Remote), AddressBookImpl (extends UnicastRemoteObject implements AddressBook), BuddyInfoInterf (interface extends Remote), BuddyInfo (the implementation, extends Unicast... implements BuddyI...), and AddressBookUser.
    The AddressBook is created on the server-side (in main() found in AddressBookImpl) and is populated with BuddyInfo's also created server-side.
    AddressBookUser is just the client accessing some info from ABook or BInfo.
    So, anyway, here's the xml file I've written to do the tasks assigned. The classes compile fine, and the jar files seem to contain the proper files. My problem is that the jar files don't execute properly. The main() in AddressBookImpl creates the ABook and binds it to the rmiregistry. When I run the server.jar that is "initially" created during the process (the one in the base dir) it works fine but this only seems to work correctly because it's in the same dir as all of the compiled classes. The copied jar file in the other directory, or even if I manually copy the server.jar file in the base dir to some other dir, causes an exception when trying to bind the AddressBook to the registry saying it can't find a stub that is definitely located in the jar. And I'm running the rmiregistry in whatever dir the server.jar is in each time:
    Exception in thread "main" java.rmi.ServerException: RemoteException occurred in
    server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
    tion is:
    java.lang.ClassNotFoundException: AddressBookImpl_Stub
    at sun.rmi.server.....
    <?xml version="1.0"?>
    <project default="packaging">
    <!-- Change location(s) to desired path(s) where client and/or
    server jar files should be copied to, else will create folders
    "client" and "server" in project directory and copy them to
    there. -->
    <property name="serverDir" location="./server"/>
    <property name="clientDir" location="./client"/>
    <!-- performs all tasks -->
    <target name="packaging">
         <!-- Compiles all files in project directory. Necessary for
         AddressBookUser.java to be compiled -->
         <javac srcdir="."/>
         <!-- RMI compiles AddressBookImpl & BuddyInfo -->
         <rmic classname="AddressBookImpl" base="."/>
         <rmic classname="BuddyInfo" base="."/>
         <!-- Creates server jar file -->
         <jar destfile="./server.jar" basedir="." includes="**.class" excludes="AddressBookUser.**">
              <manifest>
                   <attribute name="Main-Class" value="AddressBookImpl"/>
                   <attribute name="Class-Path" value="."/>
              </manifest>
         </jar>
         <!-- Creates client jar file -->
         <jar destfile="./client.jar" basedir="." includes="**.class" excludes="AddressBookImpl.** BuddyInfo.** **Skel.class">
              <manifest>
                   <attribute name="Main-Class" value="AddressBookUser"/>
                   <attribute name="Class-Path" value="."/>
              </manifest>
         </jar>
         <!-- copy jar files to specified directories -->
         <copy file="./server.jar" todir="${serverDir}"/>
         <copy file="./client.jar" todir="${clientDir}"/>     
    </target>
    </project>
    Sorry bout the length. Just want to cover my bases. Thanks for any help.

    I am also having problem in building server.jar file using Ant. I am using EJB jar file in my web application, this jar file is called remotely from server to client. Client.jar file working correctly but the server.jar file contains error which is given below:
    15:30:47,296 WARN [verifier] EJB spec violation:
    Bean : Server
    Section: 22.2
    Warning: The Bean Provider must specify the fully-qualified name of the Java cla
    ss that implements the enterprise bean's business methods in the <ejb-class> ele
    ment.
    Info : Class not found on 'com.ejb.ServerBean': No ClassLoaders found for: com.ejb.ServerBean
    15:30:47,296 ERROR [MainDeployer] Could not create deployment: file:/C:/jboss-4.0.4.GA/server/default/deploy/server.jar
    org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.
    In above error, "Class not found on 'com.ejb.ServerBean' " is given. Will there be all the classes of EJB jar file in server.jar ? I think only the interface class file i.e. Server.class and serverHome.class must be included, am I correct or not?
    Also the build.xml which I am using for creating server.jar is given below:
    <project name="ServerEJB" default="make_server_jar" basedir=".">
    <!-- Initialization variables -->
    <property environment="env" />
    <property name="app.name" value="${ant.project.name}"/>
    <property name="source.dir" value="ejbModule"/>
    <property name="build.dir" value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="distribution.dir" value="dist"/>
         <property name="server.ejb.jar.name" value="server.jar"/>
    <target name="clean" description="Deletes compiled and generated code">
    <delete dir="${build.dir}"/>
    </target>
    <target name="make_server_jar" depends="" description="Builds a server.jar with stubs for apps to use">
    <mkdir dir="${distribution.dir}" />
    <jar destfile="${distribution.dir}/${server.ejb.jar.name}" basedir="${classes.dir}">
         <exclude name="**/*Bean.class"/>
    </jar>
    </target>     
    </project>
    I am using server.jar file in server as interface which will remotely call client.jar which will be kept at client location.
    Anybody, can you provide me with the solution for this problem?...
    Thank you.

  • Updating a JAR that uses packages

    Hi There,
    I have a problem in that I am trying to update a class within a JAR which uses packages. The issue is that when updating the JAR, the class I have requested to update is simply placed in the root of the JAR and not in the required package.
    I need to to this within a Java program, so unpacking and re-packing the JAR is not an option.
    Here is what i've been trying:
    I have a class called UserProfile.class, which resides within my messages package - Structure: /messages/UserProfile.class
    When I call the update command:
    jar uf C:\AdminUI.jar E:\project\code\Eclipse_Proj\messages\UserProfile.class
    It creates the folder structure /project/code/Eclipse_Proj/messages within the JAR file and places UserProfile.class within this folder - when in fact the UserProfile.class should be placed within the /messages folder.
    Any ideas on how I can place the class in the correct folder would be much appreciated.
    Thanks very much
    K
    null

    Thanks for the reply!
    Yeah that works, but i'm trying to update the JAR from a Java program using
    Runtime.getRuntime().exec()
    but when I try to run the command Runtime.getRuntime().exec("cd c:") I get the below exception:
    java.io.IOException: CreateProcess: cd c: error=2
    I understand there is a -C parameter to temporarily change directory so I tried the following command:
    jar uf C:\AdminUI.jar -C E:\project\code\Eclipse_Proj \messages\UserProfile.class
    But this simply inserts the UserProfile.class into a jar under the following directory structure:
    project/code/Eclipse_Proj/messages/UserProfile.class
    Thanks again for your help.
    Any input much appreciated
    K

  • How to use loadjava tool to regard file in other packages/JARs?

    How do I have to set the options for the loadjava tool when I have a Java class that uses classes of another package/JAR (which I have developed by myself). I thought it was just to create a JAR containing my Java class as well as the JARs containing the other packages/classes being imported in my Java class. and then:
    loadjava -u user/passwd@hostname:1521:xxx -v -r C:\Temp\MyJAR.jar
    but I always get
    cannot find symbol    :    class MissingClass

    This is the wrong forum!
    1. Repost the question in the Database JVM forum
    Java in the Oracle Database
    2. Edit this thread and post the link to the new one and direct people to follow up there
    3. Mark this thread ANSWERED so people will follow up in the other forum.
    When you post there provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION) and review Chapter 11 Schema Objects and Oracle JVM Utilities in the Java Developers Guide
    http://docs.oracle.com/cd/B28359_01/java.111/b31225/cheleven.htm#CACFHDJE
    see '-recursivejars' in the Argument Summary section.
    >
    -recursivejars
    Normally, if the loadjava tool encounters an entry in a JAR with a .jar extension, it will load the entry as a resource. If this option is specified, then the loadjava tool will process contained JAR files as if they were top-level JAR files. That is, it will read their entries and load classes, sources, and resources.

  • Error adding package to class that is using a jar

    Hi,
    I have a class that is using a jar but I need it to be in a package so I can use it with JSP, but each time I put the package in the class I get some compile errors that the classes in the jar can't be found.
    Example:
    Compiling 1 source file to C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\build\web\WEB-INF\classes
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:22: cannot find symbol
    symbol : class PP_OpenInterface
    location: class tecno.Tecnomen
    private PP_OpenInterface pp = null;
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:23: cannot find symbol
    symbol : class PP_OpenInterface_Factory
    location: class tecno.Tecnomen
         private PP_OpenInterface_Factory ppf     = null;
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:127: cannot find symbol
    symbol : class PP_exception
    location: class tecno.Tecnomen
    public int GenericRecharge (String Subid,int monto) throws PP_exception
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:79: cannot find symbol
    symbol : variable PP_OpenInterface_FactoryHelper
    location: class tecno.Tecnomen
    ppf = PP_OpenInterface_FactoryHelper.narrow(nsRef);
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:91: cannot find symbol
    symbol : class PP_exception
    location: class tecno.Tecnomen
    catch(PP_exception ex)
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:139: cannot find symbol
    symbol : class paramRecord
    location: class tecno.Tecnomen
    paramRecord pSeq [] = new paramRecord[] {
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:139: cannot find symbol
    symbol : class paramRecord
    location: class tecno.Tecnomen
    paramRecord pSeq [] = new paramRecord[] {
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:140: cannot find symbol
    symbol : class paramRecord
    location: class tecno.Tecnomen
    new paramRecord(0,subId),
    C:\Documents and Settings\ehasbunv\Mis documentos\proyecto\mex\cc\src\java\tecno\Tecnomen.java:141: cannot find symbol
    symbol : class paramRecord
    location: class tecno.Tecnomen
    new paramRecord(1,amount),

    Checking another file, the problem is that if I'm
    trying to use a class in the default package in
    another class and put a package name in the class
    then I can't use the default package. Is there any
    workaround?Nope. Get in the habit now of making ALL of your classes belong to packages. The "no-package" is only for creating 'toy' applications with no dependencies from other packaged classes.

  • Using a JAR file as a project file

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

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

  • Error while running WDJ application using jxl.jar

    Hi Experts,
    I am using jxl.jar in my webdynpro java application in CE7.2. I added jxl.jar in java build path and place the jar file in lib directory of webdynpro DC. It shows error in development configuration perspective while building, then i created another DC of type ExternalLibrary and added jxl.jar in libraries folder, then i right click on that jar and published as archive. Then in Development configuration perspective i added ExternalLibrary project to my webdynpro DC, it doen't shows error while building.
    I deployed successfully, when i run the application, it shows the following error. Is there any fault in adding external jar to mt DC? i can't understand where the problem is?
    Error:
    java.lang.ClassNotFoundException: jxl.Workbook -
    Loader Info -
    ClassLoader name: [com.drl.bomrecipe/bomrecipe] Loader hash code: 30a86ee9 Living status: alive Direct parent loaders: [system:Frame] [interface:webservices] [interface:cross] [interface:security] [interface:transactionext] [library:webservices_lib] [library:opensql] [library:jms] [library:ejb20] [service:p4] [service:ejb] [service:servlet_jsp] [sap.com/tcwdapi] [library:tcblexceptionlib] [library:tcblloggingapi] Resources: E:\usr\sap\CE7\J00\j2ee\cluster\apps\com.drl.bomrecipe\bomrecipe\servlet_jsp\webdynpro\resources\com.drl.bomrecipe\bomrecipe\root\WEB-INF\lib\com.drl.bomrecipe~bomrecipe.jar -
        at com.sap.engine.boot.loader.MultiParentClassLoader.loadClass(MultiParentClassLoader.java:272)
        at com.sap.engine.boot.loader.MultiParentClassLoader.loadClass(MultiParentClassLoader.java:241)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:367)
    help me please, thanks in advance
    Regards,
    Pradeep Kumar G

    Hi Pradeep,
    Have you created both compilation and assembly public parts for your Ext Lib, and have you added them both to your Used DC's list?
    Also remember, since you are using an assembly public part, the 'Create Archive' and 'Deploy new archive and run' should not be used!
    Use the DC Build and DC Deploy instead.
    Hope this helps!
    Robin van het Hof

  • Issue with Packaged Jars added to project from resource Palette

    Hello!
    I am using Jdeveloper 11.1.2.2.
    I started this post thinking there was an issue having to do with packaging jars that refer to other libraries (see post Are Libraries Required?
    Now I realize it is a different issue (although that other post is relevant).
    Issue: I create a package -- a template in this case.
    I deploy it in my file system and then load it into the resource palette as a file system connection.
    I create a new application. From the resource palette, I add the jar to the view controller project, and am able to use the template in jsf files. No problem. Runs fine.
    then I load the application into subversion or I move the whole application to another directory on my computer.
    When I open the moved application (or do a checkout from subversion), I open the jsf that contains a reference to the jar, the design view is completely blank. Going to the source, I see my original code, but there are red signals in the upper-right signifying an error.
    If I run the application without fixing it, I get an error saying the template cant be found, Also, when I deployed to a standalone weblogic server, I get the same error (see the post above for this error).
    I open the project properties. The ADF Library is in the "Libraries and Classpath" and pressing edit, I can see the correct reference to the path of the jar.
    To make the application work, I have to remove the ADF Library (or at least the reference when pressing edit) and then from the resource palette, add it again to the project.
    IS THIS NORMAL? Am I doing something wrong with the initial packaging of the jar? Should I change some setting somewhere?
    How am I supposed to deploy to weblogic?
    The other posting shows an error output if I try to run the application before fixing the jar reference. I got the same darn error when deploying to weblogic.
    Would appreciate any help!
    Stuart
    Edited by: Stuart Fleming on Nov 18, 2012 4:45 AM

    Timo,
    thank you for your reply. I actually created a youtube video on this, available here: http://youtu.be/ERyLngq9hlI
    Since the video might be a little tedious to view, Here are the details. You can jump to the exciting parts of the video, if you want:
    Here is what I did:
    1. I cleaned out my system directory and the temp directory on my computer.
    2. Opened the application containing my template. Deleted the existing jar file.
    3. Started taking video....
    4. (From 40 seconds into the video) Created the jar file again.
    5. (2:55 minuts into video) Closed template applcation and Created new fusion application.
    6. (4 minutes into the video) Created model
    7. (4:15 minutes into video) in view controller added template, created a jsf page.
    8. (5 minutes into the video) Created Security and users.
    9. (6:30 minutes into the video) Created a task flow, with jsff in it, with a form on the jsff. Assigned Security to objects.
    *10. (7 minutes into the video). Ran JSF successfully.*
    11. (7:40 minutes into the video). Closed application. Copied the entire application into two directories.
    12. (8 minutes into video) Opened the first copied video. You can see that the jsf page is not accessing the template. Reviewed the View Controller project Libraries and classpath. Removed the library, re-added the jar from the resource palette. Worked fine.
    13. (9:30 minutes into video). Opened the 2nd copy of the file I intend for subversion. Showed the jsf page and the error it displays when open (same as in first copied application).
    Load application into subversion.
    14. (10 minutes into video). Check out application
    15. (10:15 minutes into video). Open JSF file. The reference to the template jar file is reading properly.
    16. (11 minutes into video). Load the original working copy into subversion.
    17. (11:30 minutes into video). Check out from subverion, but the check out failed.
    18. (12 minutes into video). Check out, and look at the jsf.  The page shows fine.
    Timo, I think this might be reported as a bug. You ought to be able to move files around on your computer. Also, the first time I checked the application out from subversion, the jsf page did not read the template.
    ALSO, when I tried to deploy the application (that contained the reference to the template jar file to weblogic), I got the same error when I ran the jsf
    first lines of that error:
    Error 500--Internal Server Error
    java.io.FileNotFoundException: /WEB-INF/ssfTemplate/SSFTemplate.jsf Not Found in ExternalContext as a Resource
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:224)
    Thank you for your time and commitment!
    Stuart
    Edited by: Stuart Fleming on Nov 18, 2012 10:13 AM

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

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

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

  • Using a Jar file into my jar project (Applet)

    Hy,
    I would like to know how I have to do to put a jar library in my jar file (containing my classes) ?
    I use only 2 classes of that particular jar library (Regex.class & RegRes.class), and when I only put the jar file (patbinfree153.jar), the applet stops when its reaches the first line where i use this class.
    this line :
    Regex Mon_Regex = new Regex("(([<][iI][mM][gG][^>]+)[sS][rR][cC][=][\"]{0,1}([^\"> ]*))");However, it works when I launch the applet in AppletViewer, but doesn't work anymore when I create a jar file, and open it through my web browser. (I signed already my jar file, and it works until it reaches this line). That it to say that the jvm can find the 2 external classes when I run the program trough Eclipse, but can't find them when I create my package .jar. (I hope I am clear)
    Do I need to extract the folders of this jar file ? Because I dont think the import works with those two classes. Or can I just put those 2 classes like my own classes, in this case, what to write for the import line ?
    the import I do :
    import com.stevesoft.pat.*;Thanks ^^

    I think I found a beginnig of solution, but I still have trouble.
    In the tutorial you gave me, it is said to add the following line in the manifest file to use jar in jar :
    Class-Path: JAR-FILE.jar(here is the source : http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html)
    I did it, it works fine locally, but when i put my html, jar, files on my web site, my applet seams not to find the other jar file again.
    Locally, the architecure is the following :
    \upload4.html
    \upload4.jar (its manifest have the class-path line linking with patbinfree153.jar)
    \patbinfree153.jar (contains 2 classes I need)I uploaded the same architecture on my web site, but it doesn't work. The applet stops when it reaches the 1st line where I need one of the patbinfree153 classes.
    Any idea ? :-)

  • How to use a jar file

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

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

  • How packages A uses packages B, Please?

    Dear All
    I have two packages and like to have the classes in A uses the Classes in B, A and B are seperate packages and each is compsed of many classes. My IDE is NetBeans 4.0, just if that important.
    Please let me know how I can uses Package B classes as easy as importing jar files.
    Cheers, khalid

    ok I will try this, I understand that you mean when
    both packahes a and b ar ein the same directory.Has nothing to do with whether the packages are in the same directory: You always provide the full package name in the import statement. Go through a tutorial or two, carefully. ...\com\mycompany\foo\Bar.class
    ...\com\mycompany\baz\quz\Splort.class
    // For Bar to use Splort:
    package com.mycompany.foo;
    import com.mycompany.baz.qux.Splort;
    public class Bar {}
    // For Splort to use Bar:
    package com.mycompany.baz.qux;
    import com.mycompany.foo.Bar;
    public class Splort {}
    One
    more to ask, What about when many classes in package
    b.You can use import whateverpakcage.*; It's generally considered more maintainable to list individual classes though.
    import a.B;
    import a.C;
    // etc.

  • Using packages breaks batch file

    Hi there, I wonder if anyone can help me here.
    I've been continuing work on somebody else's previous project, and everything is fine except for the batch file used to run the program from non development. I decided to use Eclipse to develop as opposed to the previous JCreator, and Eclipse gave an error unless I used packages, however this breaks the batch file
    Here's the orginal text from the batch file -
    java.exe -Xmx256m -classpath C:\InsTra\JARS\ant.jar;C:\InsTra\JARS\jaxen-core.jar;C:\InsTra\JARS\jaxen-jdom.jar;C:\InsTra\JARS\jdom.jar;C:\InsTra\JARS\saxpath.jar;C:\InsTra\JARS\xalan.jar;C:\InsTra\JARS\xerces.jar;C:\InsTra\JARS\xml-apis.jar;c:\InsTra\code_files InsTra
    The batch file is located in C:\InsTra, the external JARS are in a JARS subfolder, and the java and class files are in Code_files. The main class is InsTra. I get the error NoClassDefFoundError
    I've tried making the last bit Code_files.InsTra in case it needed to reference the package, but I'm new to this I'm afraid so have little experience of this sort of thing.
    Any help is welcome
    Thanks
    Daniel

    Then either your compiled class is not on the classpath, or you have not used the correct class name. Or both.
    The classpath must point to the root of the package hierarchy.
    The class name must include the package name (which is dictated by the package line at the top of your source file).
    The compiled class file must be in the correct directory.
    Given the information that you have provided, your class file should have the following path:
    c:\InsTra\code_files\Code_files\It should also have the following line at the top of the .java file:
    pacakge Code_files;Class names are case sensitive. Remember that the class path points to the root of the package hierarchy, NOT each of the directories containing class files. For example, if your classpath is thus:
    c:\fooYour class file is in:
    c:\foo\foo\Spong.classWith a package of:
    package foo;And you execute it with:
    java -classpath c:\foo foo.SpongThen it will work. The following will not:
    java -classpath c:\ foo.Spong
    java -classpath c:\foo\foo Spong
    java -classpath c:\foo\foo foo.Spong
    java -classpath c:\foo\foo Spong.class
    etc.

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

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

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

  • Run applet that uses borland jar's

    Hi!!!!!!!!
    I use JBuilder as IDE and i developed an applet that uses XYLayout. The problem i'm having is that the browser (MS Internet Explorer and Netscape) throw the same error and that is the package i used.
    How could i configure it???
    P.S. : sorry for my english!!!!!!!!!!
    Bye

    I'm writing this message again because i wasn't clear enough. I use a jar provided by Borland JBuilder:
    " com.borland.jbcl.layout.*; "
    This library isn't provided by Sun, so the when i try to run the applet from a browser, it throws an error.
    The question is: how can i "tell" the browser to "look-up" the Borland's library i use?
    Bye

Maybe you are looking for

  • Every png file I have suddenly has text that cannot be edited

    Hi everyone, every PNG file has suddenly lost the ability to edit text, I can highlight the text box, but to actually select box (or any item) I have to click and then drag it. I can select the the box and change font, size etc from the properties ba

  • Extended Display Issues

    My extended desktop screen has started randomly going into Sleep Mode while I'm using it w/ my '13 MacBook Pro.  I try disconnecting the MiniDisplay Port (to VGA) and reconnecting and nothing happens. Usually, the laptop screen also freezes.  Sometim

  • Excel Error issue

    hi i am kiran i am facing an issue with excel while renaming the excel sheet kindly provide me the solution  error is as follows YOU type  an invalid name for a sheet or chart make sure that The name that youtype doesnt exceed31 characters. the name

  • EHS - Contractor/Vendor Management

    Hi all Is there any mechanism in SAP EHS or MM module, where we can capture details such as Insurance, Environment compliances, Waste dispose/transport license details for vendors/contractors. We want to capture this information while selecting a ven

  • I need to download some previous purchases and I can't find the download button that the support articles refer to.

    I lost some of my purchased music. I read numerous support articles and it seems that the easiest solution is just to re-download those purchases to i-tunes on my pc. The problem is that the articles refer to a download button which I cannot find any