Results 1 to 9 of 9
  1. #1
    dan0 is offline Member
    Join Date
    Feb 2009
    Posts
    40
    Rep Power
    0

    Default [SOLVED] Compling errors relating to Apache package

    I'm using an Apache package; I've add it's jar file location to the classpath environment variable. When I try to compile the code via the command line I get numerous errors including:

    package org.apache.commons.httpclient does not exist
    However, when I compile and run the code in eclipse there are no errors. Prior to coding, I added the apache package to eclipse's build path as an external jar.

    Can anyone tell me why my code compiles in eclipse but not through the command line?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Can anyone tell me why my code compiles in eclipse but not through the command line?
    Because Eclipse and the command line compiler (possibly Sun's javac) are not using the same classpath.

    You mention that you are using a CLASSPATH variable. In this case the value of this variable should include the jar file which includes the org.apache.commons.httpclient package. There are often numerous jar files that all have to be mentioned on the classpath.

  3. #3
    softslate is offline Member
    Join Date
    Mar 2009
    Location
    Schenectady, NY
    Posts
    11
    Rep Power
    0

    Default

    As stated above, you need to add all the jars that Eclipse has in its classpath to the command line. In Eclipse if you right-click on the product and select Build Path -> Configure Build Path and then the Libraries tab, it should show you the jars in question.
    SoftSlate Commerce Java Shopping Cart
    www.softslate.com

  4. #4
    dan0 is offline Member
    Join Date
    Feb 2009
    Posts
    40
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    ... In this case the value of this variable should include the jar file which includes the org.apache.commons.httpclient package. There are often numerous jar files that all have to be mentioned on the classpath.
    In the case of the httpclient package there are 4 that need to be added. I've add those 4 jar files plus the folder which contains all the relevant jar files. Following is exactly what I have as my classpath variable. If my classpath declarations are incorrect, let me know.

    .;C:\Program Files\Java\jdk1.6.0_11\lib\tools.jar;C:\Program Files\Apache\commons-httpclient\comoms-httpclient-3.1jar;C:\Program Files\Apache\commons-logging\commons-logging-1.1.1.jar;C:\Program Files\Apache\commons-codec\commons-codec-1.3.jar;C:\Program Files\Apache\junit-4.5.jar;C:\Program Files\Apache
    Quote Originally Posted by softslate
    As stated above, you need to add all the jars that Eclipse has in its classpath to the command line. In Eclipse if you right-click on the product and select Build Path -> Configure Build Path and then the Libraries tab, it should show you the jars in question.
    But if I have them in my classpath environment variable, why do I need to delcare them again in the command line?
    Last edited by dan0; 03-30-2009 at 11:19 PM.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    .;C:\Program Files\Java\jdk1.6.0_11\lib\tools.jar;C:\Program Files\Apache\commons-httpclient\comoms-httpclient-3.1jar;C:\Program Files\Apache\commons-logging\commons-logging-1.1.1.jar;C:\Program Files\Apache\commons-codec\commons-codec-1.3.jar;C:\Program Files\Apache\junit-4.5.jar;C:\Program Files\Apache
    It looks like you're missing a "dot" in commons-httpclient-3.1.jar

    Why mention the Apache directory itself as part of the CLASSPATH variable?

    But if I have them in my classpath environment variable, why do I need to delcare them again in the command line?
    You don't have to put them all on the command line, but you do need to have them all on the classpath that the compiler uses. This classpath will either be the directories and jar files mentioned on the command line (using the -cp syntax) or the value of the CLASSPATH variable but not both. Personally I leave the variable unset: it can't be wrong (==different to what I assume) if it doesn't exist.

  6. #6
    dan0 is offline Member
    Join Date
    Feb 2009
    Posts
    40
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    It looks like you're missing a "dot" in commons-httpclient-3.1.jar

    Why mention the Apache directory itself as part of the CLASSPATH variable?
    I added the apache directory just to make sure the jar files could be found.

    Thanks for catching that I was missing the "dot." Once I corrected that, the code complied/ran both through eclipse and javac cmd line on my pc.

    I do have one last question pertaining to compiling and running code dependent on external packages (packages other than the java api).

    When I run my code from a web server as an applet, everything works until I get to the code which relies on the HttpClient package. The error is a result of not being able to find the particular class, why is that? Do I need to add have the jar files on the web server as well? The java console displays the following errors:

    Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity
    ...
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.methods.RequestEntit y
    ...
    Caused by: java.io.IOException: open HTTP connection failed:http://xxx.xxx.xxx.xxx/site/php/org/...stEntity.class
    ...
    Last edited by dan0; 03-31-2009 at 12:23 AM.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    When I run my code from a web server as an applet, everything works until I get to the code which relies on the HttpClient package. The error is a result of not being able to find the particular class, why is that?
    I'm not completely sure I understand this. (Perhaps the full runtime stack trace would help?) But if you are running an applet then you are running it within the client browser, not the server. Typically you need to mention all of the archive (jar) files as part of the applet/object/embed tag on the HTML page. (Details in Sun's Deploying Applets tutorial.)

    The applet will also be subject to security restrictions when run this way - these will be documented in Apache's documentation and are described in a general way in the Security Restrictions section of the same tutorial.

  8. #8
    dan0 is offline Member
    Join Date
    Feb 2009
    Posts
    40
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    I'm not completely sure I understand this. (Perhaps the full runtime stack trace would help?)
    Let me clarify. The problem occurs when I run the applet (in my web browser) as opposed to running it as an application via eclipse or the java command line. At the bottom of this post is the complete stack trace; from what I can make out from it, particular classes from the Apache package cannot be found.

    Following is my applet tag:
    Java Code:
    <applet code="projects.web.UploadApplet" archive="../applets/webtools.jar" width="700" height="600"></applet>
    In my applet tag I indicate the starting point of the applet ( the class that has init() method ) and the location of the applet jar file. Am I supposed to have the Apache package on the server and indicate its location on the server in the applet tag?

    Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity
    at projects.web.AppletGUI$ButtonHandler.actionPerform ed(AppletGUI.java:169)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.methods.RequestEntit y
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 25 more
    Caused by: java.io.IOException: open HTTP connection failed:http://xxx.xxx.xxx.xxx/site/php/org/...stEntity.class
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 29 more

  9. #9
    dan0 is offline Member
    Join Date
    Feb 2009
    Posts
    40
    Rep Power
    0

    Default

    Steps taken to resolve the problem:

    1. Add the relevant jar files to the web server
    2. Modify the manifest file to include the "Class-Path" to the jar files

Similar Threads

  1. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  2. Replies: 0
    Last Post: 11-15-2008, 07:29 AM
  3. makeButton errors
    By ljk8950 in forum AWT / Swing
    Replies: 12
    Last Post: 08-10-2008, 01:10 AM
  4. Compling problem
    By denisdoherty in forum New To Java
    Replies: 28
    Last Post: 04-22-2008, 03:25 PM
  5. help with these errors
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 04:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •