eclipsemavenbuildokhttpbuildpath

Steps to add okhttp to existing Java project in Eclipse


I'm old-school and so have always just added jar files to the build path in Eclipse (4.26.0), but I want to modernize. Everything I see talks about maven, so I went into Window > Show View > Other... and selected Maven Repositories, but can't find anything to do there.

Then I tried right-click New > Other...> Maven > Maven Project which directs me to Select and Archetype, but under "All Catalogs", I do not find "okhttp".

I see that https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp/4.12.0 exists, and that's what I want in my project. I tried "Add Remote Catalog...", but when I put https://mvnrepository.com/maven2/archetype-catalog.xml as the catalog file, it says "Remote catalog is empty", so my guess at what the catalog file xml file name is can't be right. I don't see where on mvnrepository.com they tell me what the catalog xml file URL is.

How can I add okhttp to my Eclipse project? Should I just give up and go back to jar files?


Solution

  • If you want to switch to maven, it is essentially four steps:

    I'd recommend to use a template hello world project, so you can conveniently start off with something that works, and inspect file structure, find inspiration from... You can create such a sample project with an archetype:

      mvn archetype:generate \
      -DgroupId=com.stackoverflow \
      -DartifactId=MavenHelloWorld \
      -DarchetypeArtifactId=maven-archetype-quickstart \
      -DinteractiveMode=false
    

    (replace com.stackoverflow by whatever reversed domain fits you as a developer / company)

    A while ago I've created a "getting started with maven" page for my students, where I explain layout, minimal pom.xml and some off-the-shelf maven configuration building blocks. Might be a good side-read to get started with the project migration.