If you use maven in your java project, you should use pom.xml to add dependencies that your java project required. But sometimes you may need to add the third-party library jar files directly in your java project instead of using maven pom.xml.
This article will tell you another method that does not use maven download jar files but download the jar files from the maven repository directly. It will also tell you how to add the download jar files in your eclipse java project java build path.
1. Download Jar From Maven Central Repository Steps.
- Open a web browser and browse http://mvnrepository.com/ to goto maven central repository website.
- Input the jars maven groups, artifacts, or categories name in the search box and click the Search button. Then it will list all the related library links.
- For example, we want to download the google GSON library jars in the maven central repository, we just type GSON and click Search.
- Click the Gson link to go to the library detail page.
- Click the version number that you need, in this example, we click version link 2.8.5 to go to that version detail page.
- In the GSON version detail page, after the Files column, you can see a link which link text is jar (235 K ). This is just the Gson jar file link.
- Click the above link to download the Gson version 2.8.5 jar file.
2.Download Jar From maven.org.
- There is another maven repository that you can download jar files from.
- Open a web browser and browse the URL maven.org or search.maven.org .
- Input the jar library group name or artifact name in the search box, it will list all matched jar libraries.
- If you know the jar library group name, artifact name, and version, you can input something like g:com.dolphindb AND a:jdbc AND v:1.10.2 in the search box, this can make the search more accurate.
- Now it will list the matched maven jar library on the page, click the Download link at the end of the row, then you can select download jar, javadoc.jar,pom or sources.jar file.
- But if you browse into some artifact detail webpage ( for example https://search.maven.org/artifact/com.google.code.gson/gson-parent/2.8.6/pom ), when you click the Download link at the top right corner of the page, it will only list one item pom. In such a case, you can search the artifact name in the search box, and click each listed artifact’s Download link, and you can find some link can download the jar item and some link can only download the pom.
3. Add Download Jars Into Java Project.
After download jar files from the maven central repository, before you can use them, you need to add them to your java project. Below are the steps to add the jar to your java project using eclipse.
- Right-click the java project name in eclipse, and click Properties menu item in the popup menu list.
- Click Java Build Path menu item in the left panel of the popup window, click the Libraries tab in the right panel, and click Add External JARs button.
- Browse to the folder where the downloaded jar file is saved and click the Open or Save button to add it to the java build path. Then click Apply and Close button to add the jars to the java project. Now you can use the jars contained java classes in your java code.