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 8 of 8

Thread: Importing Apache Commons?

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Importing Apache Commons?

    Hi!

    I've got this annoying error message when trying to import:
    import org.apache.commons.codec.binary.Hex.encodeHex;

    "Import org.apache.commons.codec cannot be resolved", which after searching seems to be a somewhat common problem. The solution being to go to: FileUpload - Home and download some jar file and add it to the /web-inf/lib folder. I've done this (or at least I think I have, the file is every so confusing), yet the error persists even after adding the jar file in "add external jar files" and restarting eclipse.

    The jar file I added is called "commons-fileupload-1.3.1.jar" which is the only one I could find in the zip file. I've searched around looking at numerous threads about the issue, several of them sadly several years old, with no success.

    What exactly am I doing wrong? Surely installing a library to eclipse shouldn't be this complicated?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Importing Apache Commons?

    It's a common problem for those learning to use their IDE of any kind. I typically use Method 2 in this link, but that may not be the best approach for a project that may be exported in the future.

  3. #3
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Importing Apache Commons?

    I'm afraid even that doesn't seem to work, I tried several of the Apache folders, zips, java files, none of it removed the error message.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Importing Apache Commons?

    I tried several of the Apache folders, zips, java files
    This comment is confusing. What jar file do you have? Never mind, it sounds like you have them all except the right one added the right way.

    Step by step:

    Did you download this library?: org.apache.commons.codec (Download the binary.)

  5. #5
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Importing Apache Commons?

    Hm, no I downloaded these ones: FileUpload - Download Apache Commons FileUpload, tried both the bin and source, but no wonder they didn't work if neither was correct. ^^

    I've downloaded the one you linked, what folder should I place it in?

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Importing Apache Commons?

    Any folder you'd like. I keep a separate folder for all of my 3rd party .jar files. You can then add that folder to your classpath, and/or add each .jar to the project's builders (per the earlier link) in your IDE. The specific approach you use may only matter when it comes time to export the completed project, if you need to.

  7. #7
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Importing Apache Commons?

    Strange, something is still wrong.

    1: I download the file commons-codec-1.9-bin.zip
    2: I extract the folder to a location where I can easily find it.
    3: I right click the project, go down to build path, and select "configure build path".
    4: I press add variable.
    5: I press configure variables.
    6: I press new.
    7: I enter the name "APACHE_JARS, press folder and locate to the commons-codec-1.9-bin folder, I select it and press OK.
    (Tried stopping here, still recieve error)
    8: I press OK, eclipse rebuilds.
    9: I select the APACHE_JARS and press Extend.
    10: I select all of the jar files available:
    commons-codec-1.9-javadoc.jar
    commons-codec-1.9-sourcer.jar
    commons-codec-1.9-test-sourcers.jar
    commons-codec-1.9-tests.jar
    commons-codec-1.9.jar

    I press OK until all of the windows are closed, and still have the error. Restarting eclipse doesn't solve it.

    Edit:

    On second look, it seems it did and didn't solve the issue, it accepts:
    import org.apache.commons.codec.binary.*;

    But not:
    import org.apache.commons.codec.binary.Hex.encodeHex;

    With the error message of: "The import org.apache.commons.codec.binary.Hex.encodeHex cannot be resolved"

    It doesn't seem to be able to find anything past binary, so the issue remains. =/

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Importing Apache Commons?

    You've made progress, successfully added the needed .jar file to your project, but now the specific import doesn't exist in the latest version of the Apace Commons Codec package. (Or maybe it never existed.) You'll either need to revert to the earlier version that did have the necessary import, OR inspect the later packages and adjust the import as needed.

    I found this discussion among others having the same problem with a possible workaround near the bottom.

Similar Threads

  1. Exception at org.apache.commons.ssl.ASN1Util.main
    By KhD in forum Web Frameworks
    Replies: 0
    Last Post: January 2nd, 2014, 12:02 AM
  2. How to solve user defined from apache commons math
    By The_Legend in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 18th, 2013, 03:55 PM
  3. need help with 'org.apache.commons.net.ftp.FTPClient'
    By rtumatt in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 22nd, 2013, 07:02 PM
  4. Uploading File to server ( Apache.commons.net)
    By quirell in forum Java Networking
    Replies: 5
    Last Post: November 11th, 2012, 11:06 PM
  5. problem while sending email using org.apache.commons.mail.*
    By gurleen in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2012, 11:21 AM