How to import new APIs into Java?

心已入冬 提交于 2019-12-11 10:02:20

问题


I'm a beginner programmer and am looking to utilize some features from within an API I came across on the internet, http://ini4j.sourceforge.net/ is the link to the API, it allows Java to interface with .ini files. I've downloaded the archive containing all the files necessary to import, but I'm not sure how to import them into Eclipse so that I can use them with my Java project, any help would be greatly appreciated.


回答1:


The easiest way is to create a new folder under your project e.g. lib and copy all the jar files of the library you want to use to this lib folder (note you can do all of this from inside eclipse)

Refresh your eclipse project, so the new files show up. Right click on them and select Build Path -> Add to Build Path

You can also right click on your project and select Build Path -> Configure Build Path




回答2:


I would actually recommend taking a look at maven. It is a tool that helps you manage your builds, dependencies, ...

This way if you ever want to check your code into a source code repository you don't need to also commit your jar files, and it makes it much easier to update your files.

Quick sample:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.kanescharles.iniProject</groupId>
    <artifactId>iniProject</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>iniTest</name>
    <url>http://www.kanecharles.com/iniTest</url>
    <build>
        <finalName>iniTest</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.ini4j</groupId>
            <artifactId>ini4j</artifactId>
            <version>0.5.2</version>
        </dependency>        
    </dependencies>  
</project>

For Eclipse you have the m2eclipse plugin, and if you want to look up dependencies I would recommend mvnRepository



来源:https://stackoverflow.com/questions/14766854/how-to-import-new-apis-into-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!