Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Using 3rd Party JAR Files

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using 3rd Party JAR Files

    I have been working through a java textbook. I have a reasonable grasp of the basic concepts of java programming but one area I am always struggling with is getting the system to recognise 3rd party jar files. I just never seem to be able to get them to work.

    I set up the classpath and add them to the directory in the classpath but I always get compiler errors or run time errors not finidng the class. For example, in order to make the apache xml-RPC jar files work I read that all I had to do was add xmlrpc-2.0.jar and xmlrpc-2.0-applet.jar to the classpath. I set the classpath to c:\program files\java\jdk1.6.0_13\lib\ext and put theses files in there, I then tried to compile a piece of example code out of the textbook which worked. However, when I ran the program I got:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
    at org.apache.xmlrpc.XmlRpc.createTypeFactory(XmlRpc. java:238)
    at org.apache.xmlrpc.XmlRpc.<init>(XmlRpc.java:193)
    at org.apache.xmlrpc.XmlRpcClientResponseProcessor.<i nit>(XmlRpcClientResponseProcessor.java:48
    at org.apache.xmlrpc.XmlRpcClientWorker.<init>(XmlRpc ClientWorker.java:43)
    at org.apache.xmlrpc.XmlRpcClient.getWorker(XmlRpcCli ent.java:347)
    at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClien t.java:190)
    at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClien t.java:184)
    at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClien t.java:177)
    at SiteClient.getRandomSite(SiteClient.java:27)
    at SiteClient.main(SiteClient.java:14)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at sun.misc.Launcher$ExtClassLoader.findClass(Launche r.java:229)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    ... 10 more

    The program itself connects to the author of the books test server and calls a remote procedure called getRandomSite() which returns 3 string variables - url, title and description and outputs them to the console.
    The code from the application is below, it is taken from SAMS Teach Yourself Java in 21 Days:

    import java.io.*;
    import java.util.*;
    import java.net.*;
    import org.apache.xmlrpc.*;
     
    public class SiteClient{
    	String url;
    	String title;
    	String description;
    	public static void main(String[] args){
    			SiteClient sClient = new SiteClient();
    			try {
    					Vector response = new Vector();
    					response = sClient.getRandomSite();
    					if (response.size() > 0) {
    							sClient.url = response.get(1).toString();
    							sClient.title = response.get(2).toString();
    							sClient.description = response.get(3).toString();
    							System.out.print("Url: " + sClient.url + "\nTitle: " + sClient.title + "\nDescription: " + sClient.description);
    						} 
    				}	      catch (IOException ioe) { System.out.print("IO Exception: " + ioe.getMessage()); }
    						  catch (XmlRpcException xrpc) { System.out.print("XML Remote Procedure Call Error: " + xrpc.getMessage()); }
    			}
    	public Vector getRandomSite() throws IOException, XmlRpcException{
    			Vector params = new Vector();
    			XmlRpcClient client = new XmlRpcClient("http://cadenhead.org:4413");
    			Vector result = (Vector) client.execute("dmoz.getRandomSite", params);
    			return result;
    		}	
    }

    Can anyone tell me what I'm doing wrong, I've had this problem with most 3rd party jars but was able to get the XOM API working, I haven't done anything differently here.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Using 3rd Party JAR Files

    Hello oss_2008,

    Welcome to the Java Programming Forums

    What IDE are you using?

    If you are not already using Eclipse then I suggest you download it! It's really easy to add 3rd party jar files into Eclipse.

    http://www.javaprogrammingforums.com...plication.html

    Try creating a folder called 'lib' in your Java projects directory and add the .jar files in there.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using 3rd Party JAR Files

    Thanks for the welcome JavaPF and the help. I will give this a try and post back how I get on. At the minute I'm not using a development environment just text editor + jdk.

  4. #4
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using 3rd Party JAR Files

    I've downloaded, installed Eclipse and have had a go importing third party java applications. It was showing my system library in jdk\jre\lib\ext. I moved all of the relevant jar files into this directory, they show up in the tree but I am still getting the same message when I go to run the app.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Thumbs up Re: Using 3rd Party JAR Files

    Quote Originally Posted by oss_2008 View Post
    I've downloaded, installed Eclipse and have had a go importing third party java applications. It was showing my system library in jdk\jre\lib\ext. I moved all of the relevant jar files into this directory, they show up in the tree but I am still getting the same message when I go to run the app.
    In Eclipse, look at the Package Explorer window on the left. Select the Java project you are working on and right click. Click Properties. Then click Java Build Path. Click Add External Jars.

    Select the .jar files in question and click open.

    Try again and let me know what happens!?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using 3rd Party JAR Files

    Hi thanks for your help again.

    It's the same problem I'm afraid. It imports the contents of the jar files. When I expand the jar files in the tree they have all of the classes that I am importing into my program, I go to run > run as > java application and it outputs the same error.

  7. #7
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Using 3rd Party JAR Files

    Where can I download the apache xml-RPC jar files from?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  8. #8
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using 3rd Party JAR Files

    That's the main website below, the textbook told me to download xmlrpc-2.0.jar and xmlrpc-2.0-applet.jar which weren't even in the download on the apache site so I located them through find jar website. I have added all of the files downloaded to the build path now and still the same problem. Thank you for all the help by the way.

    ws-xmlrpc - Downloads

    JAR Search Engine - findJAR.com

  9. #9
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Using 3rd Party JAR Files

    Thanks for that.

    I downloaded the .jar files and loaded them in Eclipse. They import fine and Eclipse recognizes the imports.

    When I attempt to run the code I get the same error message as you. Now I know that this isn't because we have loaded the .jar files incorrectly because they are definitely there.

    I think the problem is with the .jar files themselves. The problem is caused by org.apache.commons.codec.DecoderException

    I have a feeling this could be missing from the jars?!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  10. #10
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using 3rd Party JAR Files

    You mean a missing class that should be in the jars or a missing jar altogether? Glad to know I'm not doing anything wrong in particular.

  11. #11
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Using 3rd Party JAR Files

    I have just looked within the jars and there is no org.apache.commons

    This class is obviousally needed but missing?!?!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  12. #12
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using 3rd Party JAR Files

    OK found the jar file in question it was commons-codec.jar, imported it into my classpath and the app now runs with a connection timeout IO exception which is probably down to the server not being available at the minute. Thank you for your help I will definately be back here in future.

  13. #13
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Thumbs up Re: Using 3rd Party JAR Files

    Quote Originally Posted by oss_2008 View Post
    OK found the jar file in question it was commons-codec.jar, imported it into my classpath and the app now runs with a connection timeout IO exception which is probably down to the server not being available at the minute. Thank you for your help I will definately be back here in future.
    Brilliant! Glad we found the solution. I'm sure I will speak to you again soon
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Java program which can list all files in a given directory
    By JavaPF in forum Java Programming Tutorials
    Replies: 8
    Last Post: July 9th, 2013, 03:38 AM
  2. getting files in the linux server
    By Truffy in forum Java Networking
    Replies: 36
    Last Post: June 22nd, 2009, 06:32 PM
  3. FileNotFound error while working with XML files in windows
    By ochieng in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 14th, 2008, 07:56 AM