简体   繁体   中英

How to include an external library into your project properly

I am using the Keyczar Java library to encrpyt and decrpyt information.

I am trying to do the below as stated on the main site

package testing2;
import testing2.org.keyczar;

public class Testing2 
{
    public static void main(String[] args) 
    {    
        Crypter crypter = new Crypter("/path/to/your/keys");
    }
}

The compiler gives the following error : Crypter symbol cant be found

I suspect that the cause of the problem is that I did not include my external library files properly

This is how i have included my files

在此处输入图片说明

What am i doing wrong ???

Download Keyczar from here

To include external library/ JARs into your project follow following steps:

  • Right click on project -> Build path -> Configure build path
  • Go to Libraries tab and click Add External JARs -> Select the library/ JARs you want to include. As shown in below image:

在此处输入图片说明

Also if you are exporting your project as an Executable JAR , then go to Order and Export and select the JAR(s) that you want to included in your executable jar, as shown in below image.

在此处输入图片说明

Also in your above code I can see that there is no import statement for Crypter class. If you have added external JARs by following above procedure, then you can press Ctrl + Shift + O to solve import problems in Eclipse.

I would suggest you to use Maven: http://maven.apache.org/

It is most recommended and most widely used software management tool. It can manage project build and dependencies pretty easily. Most of the production level application in the current scenario use Maven.

You also do not need to worry about the dependencies of your project, which really helps when your application has heavy external dependencies. The project will download the dependencies direct from the maven repository and you won't have to carry them with the project.

If you just want to test out your application you can add a library through your IDE, and it seems like you are using NetBeans check here to see how to do so.

As per long term project maintainability and sustainability it's good if you use a project management tool like Maven or Ant

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM