Run HttpComponents Core Example


How to run the HttpComponents Core Example? I have installed.



If you have installed, you can follow this tutorial to run the HttpComponents Core Example:

1. Open the example program file from \fyicenter\httpcomponents-core-4.4.6\examples\org\apache\http\examples\ folder:

 * ====================================================================
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * ...
package org.apache.http.examples;

import org.apache.http.util.VersionInfo;

 * Prints version information for debugging purposes.
 * This can be used to verify that the correct versions of the
 * HttpComponent JARs are picked up from the classpath.
public class PrintVersionInfo {

    /** A default list of module packages. */
    private final static String[] MODULE_LIST = {
        "org.apache.http",              // HttpCore
        "org.apache.http.nio",          // HttpCore NIO
        "org.apache.http.client",       // HttpClient

     * Prints version information.
     * @param args      command line arguments. Leave empty to print version
     *                  information for the default packages. Otherwise, pass
     *                  a list of packages for which to get version info.
    public static void main(String args[]) {
        String[]    pckgs = (args.length > 0) ? args : MODULE_LIST;
        VersionInfo[] via = VersionInfo.loadVersionInfo(pckgs, null);
        System.out.println("version info for thread context classloader:");
        for (int i=0; i<via.length; i++)


        // if the version information for the classloader of this class
        // is different from that for the thread context classloader,
        // there may be a problem with multiple versions in the classpath

        via = VersionInfo.loadVersionInfo
            (pckgs, PrintVersionInfo.class.getClassLoader());
        System.out.println("version info for static classloader:");
        for (int i=0; i<via.length; i++)

2. Compile and run the example with Java SE 8 JDK:

   -cp ..\lib\httpcore-4.4.6.jar org\apache\http\examples\

   -cp .;..\lib\httpcore-4.4.6.jar org.apache.http.examples.PrintVersionInfo
version info for thread context classloader:

version info for static classloader:


Using HttpComponents API in Java Programs

⇒⇒FAQ for Apache HttpComponents-*.jar

2017-11-02, 183👍, 0💬