Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2070

Newbie is puzzled over CLASSPATH

From Redcat <redcat@catfolks.net>
Newsgroups comp.lang.java.help
Subject Newbie is puzzled over CLASSPATH
Date 2012-09-02 22:39 +0000
Message-ID <aai5hsFppkU1@mid.individual.net> (permalink)

Show all headers | View raw


I've been programming for a good while, but am new to Java. I've been 
trying to answer my own questions by doing online research, but I've seem 
to hit a wall.

I have Java EE installed at /usr/local/glassfish3. I've got JAVAHOME set 
to /usr/local/glassfish3/jdk7 and CLASSPATH set to /usr/local/glassfish3/
jdk7/lib. All was seeming to go smoothly with my Java development until I 
installed Apache HTTPComponents. I copied the jar files to /usr/local/
glassfish3/jdk7/lib.

I've got a simple HTTPComponents example program that I grabbed off the 
web. When I run javac against it I get errors reporting that the 
HTTPComponents files can't be found. Another simple Java program that 
displays my classpath, and it shows the path I set it to.

My example program is:
package org.apache.http.examples.client;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

/**
 * A simple example that uses HttpClient to execute an HTTP request 
against
 * a target site that requires user authentication.
 */
public class ClientAuthentication {

    public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope("50.17.237.39", 80),
                    new UsernamePasswordCredentials("test", "test"));

            HttpGet httpget = new HttpGet("http://50.17.237.39/test");
            System.out.println("executing request" + 
httpget.getRequestLine());
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();

            System.out.println
("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + 
entity.getContentLength());
            }
            EntityUtils.consume(entity);
        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }
}

The error message I get is:
dan@dan-Aspire-4730Z:~/development$ javac ClientAuthentication.java 
ClientAuthentication.java:3: error: cannot find symbol
import org.apache.http.HttpEntity;
                      ^
  symbol:   class HttpEntity
  location: package org.apache.http
ClientAuthentication.java:4: error: cannot find symbol
import org.apache.http.HttpResponse;
                      ^
  symbol:   class HttpResponse
  location: package org.apache.http
ClientAuthentication.java:5: error: package org.apache.http.auth does not 
exist
import org.apache.http.auth.AuthScope;
                           ^
ClientAuthentication.java:6: error: package org.apache.http.auth does not 
exist
import org.apache.http.auth.UsernamePasswordCredentials;
                           ^
ClientAuthentication.java:7: error: package org.apache.http.client.methods 
does not exist
import org.apache.http.client.methods.HttpGet;
                                     ^
ClientAuthentication.java:8: error: package org.apache.http.impl.client 
does not exist
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
ClientAuthentication.java:9: error: package org.apache.http.util does not 
exist
import org.apache.http.util.EntityUtils;
                           ^
ClientAuthentication.java:18: error: cannot find symbol
        DefaultHttpClient httpclient = new DefaultHttpClient();
        ^
  symbol:   class DefaultHttpClient
  location: class ClientAuthentication
ClientAuthentication.java:18: error: cannot find symbol
        DefaultHttpClient httpclient = new DefaultHttpClient();
                                           ^
  symbol:   class DefaultHttpClient
  location: class ClientAuthentication
ClientAuthentication.java:21: error: cannot find symbol
                    new AuthScope("50.17.237.39", 80),
                        ^
  symbol:   class AuthScope
  location: class ClientAuthentication
ClientAuthentication.java:22: error: cannot find symbol
                    new UsernamePasswordCredentials("test", "test"));
                        ^
  symbol:   class UsernamePasswordCredentials
  location: class ClientAuthentication
ClientAuthentication.java:24: error: cannot find symbol
            HttpGet httpget = new HttpGet("http://50.17.237.39/test");
            ^
  symbol:   class HttpGet
  location: class ClientAuthentication
ClientAuthentication.java:24: error: cannot find symbol
            HttpGet httpget = new HttpGet("http://50.17.237.39/test");
                                  ^
  symbol:   class HttpGet
  location: class ClientAuthentication
ClientAuthentication.java:27: error: cannot find symbol
            HttpResponse response = httpclient.execute(httpget);
            ^
  symbol:   class HttpResponse
  location: class ClientAuthentication
ClientAuthentication.java:28: error: cannot find symbol
            HttpEntity entity = response.getEntity();
            ^
  symbol:   class HttpEntity
  location: class ClientAuthentication
ClientAuthentication.java:35: error: cannot find symbol
            EntityUtils.consume(entity);
            ^
  symbol:   variable EntityUtils
  location: class ClientAuthentication
16 errors

I even tried to point the compiler to the directory into which I 
extracted the file, with:
javac -cp /home/dan/Downloads/httpcomponents-client-4.2.1/lib:$CLASSPATH 
ClientAuthentication.java
and get the same results.

I'm obviously missing something. Could anyone point me to what I might be 
overlooking?

Back to comp.lang.java.help | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Newbie is puzzled over CLASSPATH Redcat <redcat@catfolks.net> - 2012-09-02 22:39 +0000
  Re: Newbie is puzzled over CLASSPATH Jeff Higgins <jeff@invalid.invalid> - 2012-09-02 19:53 -0400
    Re: Newbie is puzzled over CLASSPATH Jeff Higgins <jeff@invalid.invalid> - 2012-09-02 20:22 -0400
  Re: Newbie is puzzled over CLASSPATH Jeff Higgins <jeff@invalid.invalid> - 2012-09-02 20:01 -0400
    Re: Newbie is puzzled over CLASSPATH Jeff Higgins <jeff@invalid.invalid> - 2012-09-02 20:08 -0400
      Re: Newbie is puzzled over CLASSPATH Lew <noone@lewscanon.com> - 2012-09-04 03:13 -0700
  Re: Newbie is puzzled over CLASSPATH markspace <-@.> - 2012-09-02 18:04 -0700
    Re: Newbie is puzzled over CLASSPATH Lew <noone@lewscanon.com> - 2012-09-04 03:17 -0700
  Re: Newbie is puzzled over CLASSPATH Knute Johnson <nospam@knutejohnson.com> - 2012-09-02 18:32 -0700
  Re: Newbie is puzzled over CLASSPATH Roedy Green <see_website@mindprod.com.invalid> - 2012-09-03 02:07 -0700

csiph-web