简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM