How to import a jar in Eclipse

前端 未结 10 1415
挽巷
挽巷 2020-11-21 06:54

How do I import a jar in Eclipse?

相关标签:
10条回答
  • 2020-11-21 07:23

    Here are the steps:

    1. click File > Import. The Import window opens.

    2. Under Select an import source, click J2EE > App Client JAR file.

    3. Click Next.

    4. In the Application Client file field, enter the location and name of the application client JAR file that you want to import. You can click the Browse button to select the JAR file from the file system.

    5. In the Application Client project field, type a new project name or select an application client project from the drop-down list. If you type a new name in this field, the application client project will be created based on the version of the application client JAR file, and it will use the default location.

    6. In the Target runtime drop-down list, select the application server that you want to target for your development. This selection affects the run time settings by modifying the class path entries for the project.

    7. If you want to add the new module to an enterprise application project, select the Add project to an EAR check box and then select an existing enterprise application project from the list or create a new one by clicking New.

      Note: If you type a new enterprise application project name, the enterprise application project will be created in the default location with the lowest compatible J2EE version based on the version of the project being created. If you want to specify a different version or a different location for the enterprise application, you must use the New Enterprise Application Project wizard.

    8. Click Finish to import the application client JAR file.

    0 讨论(0)
  • 2020-11-21 07:26

    In eclipse I included a compressed jar file i.e. zip file. Eclipse allowed me to add this zip file as an external jar but when I tried to access the classes in the jar they weren't showing up.

    After a lot of trial and error I found that using a zip format doesn't work. When I added a jar file then it worked for me.

    0 讨论(0)
  • 2020-11-21 07:28

    Adding external Jar is not smart in case you want to change the project location in filesystem.

    The best way is to add the jar to build path so your project will compile if exported:

    1. Create a folder called lib in your project folder.

    2. copy to this folder all the jar files you need.

    3. Refresh your project in eclipse.

    4. Select all the jar files, then right click on one of them and select Build Path -> Add to Build Path

    0 讨论(0)
  • 2020-11-21 07:29

    You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar. A quick demo here.

    enter image description here

    The above solution is obviously a "Quick" one. However, if you are working on a project where you need to commit files to the source control repository, I would recommend adding Jar files to a dedicated library folder within your source control repository and referencing few or all of them as mentioned above.

    0 讨论(0)
  • 2020-11-21 07:34

    Two choices:

    1/ From the project:

    alt text

    2/ If you have already other jar imported, from the directory "References Libraries":

    alt text

    Both will lead you to this screen where you can mange your libraries:

    alt text

    0 讨论(0)
  • 2020-11-21 07:35

    Just a comment on importing jars into Eclipse (plug-in development) projects:

    In case you are developing Eclipse plug-ins, it makes sense to use Eclipse's native bundling mechanism instead of just importing the jar into a plug-in project. Eclipse (or better its underlying OSGi runtime, Equinox) uses so-called bundles which contain some more information than plain jars (e.g., version infos, dependencies to other bundles, exported packages; see the MANIFEST.MF file). Because of this information, OSGi bundles can be dynamically loaded/unloaded and there is automatic dependency resolution available in an OSGi/Eclipse runtime. Hence, using OSGi bundles instead of plain jars (contained inside another OSGi bundle) has some advantages.

    (BTW: Eclipse plug-ins are the same thing as OSGi bundles.)

    There is a good chance that somebody already bundled a certain (3rd party) library as an OSGi bundle. You might want to take a look at the following bundle repositories:

    • http://www.springsource.com/repository/app/
    • http://download.eclipse.org/tools/orbit/downloads/
    • http://www.osgi.org/Repository/HomePage
    0 讨论(0)
提交回复
热议问题