maven build error: package org.apache.http does not exist

Go To StackoverFlow.com

1

I am attempting to send a simple HTTP post from a java program (for deploying on Heroku). I started with the demo project here. Using mvn package builds the project successfully.

I then added my own additional file TestPost.java with a few lines of code, added it to the pom.xml, and still built fine.

Then I tried to add the HTTP code from this example (minus the package line), which uses the Apache HttpClient library.

Using mvn package results in the following error:

package org.apache.http does not exist 

After searching for solutions I tried including a dependency in the pom.xml:

<dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.2</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

My understanding was that this should force a download of the necessary package but no download was shown on the next compile (just the same error), and the package is not visible in my user .m2\repository\ folder.

I tried inserting this dependency at different points in my pom.xml without success.

Why is the apache library not being downloaded? Please note that I am new to maven.

2016-07-04 14:43
by Andrew
org.http.apache.http isn't the correct package name. It is org.apache.http - Tunaki 2016-07-04 14:50


5

Here is the pom.xml that you should have if indeed you need to depend on httpclient.

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>demo</groupId>
    <artifactId>httpclient-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>httpclient-demo</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
    </dependencies>
</project>

Now if you put your Java sources in src/main/java, where src and pom.xml are in the same directory, Maven should resolve the dependency from your local repository, and download it, should it not already be there. Your local repository is defined in the conf/settings.xml in your Maven installation directory.

2016-07-04 15:05
by Arthur Noseda
This solved it, thank you! Thought I had tried the dependencies in that position in the pom.xml but obviously not.. - Andrew 2016-07-06 13:00