Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2070 > unrolled thread
| Started by | Redcat <redcat@catfolks.net> |
|---|---|
| First post | 2012-09-02 22:39 +0000 |
| Last post | 2012-09-03 02:07 -0700 |
| Articles | 10 — 6 participants |
Back to article view | Back to comp.lang.java.help
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
| From | Redcat <redcat@catfolks.net> |
|---|---|
| Date | 2012-09-02 22:39 +0000 |
| Subject | Newbie is puzzled over CLASSPATH |
| Message-ID | <aai5hsFppkU1@mid.individual.net> |
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?
[toc] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-09-02 19:53 -0400 |
| Message-ID | <k20rg9$pc0$1@dont-email.me> |
| In reply to | #2070 |
On 09/02/2012 06:39 PM, Redcat wrote: > 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. This may help <http://docs.oracle.com/javase/7/docs/technotes/tools/> especially the link to "Setting the Classpath" <http://docs.oracle.com/javase/7/docs/technotes/tools/#general> and the javac documentation further down the page.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-09-02 20:22 -0400 |
| Message-ID | <k20t6r$1rv$1@dont-email.me> |
| In reply to | #2071 |
On 09/02/2012 07:53 PM, Jeff Higgins wrote: > On 09/02/2012 06:39 PM, Redcat wrote: > >> 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. > This may help > <http://docs.oracle.com/javase/7/docs/technotes/tools/> > especially the link to "Setting the Classpath" > <http://docs.oracle.com/javase/7/docs/technotes/tools/#general> > and the javac documentation further down the page. You should probably read "JDK File Structure" too. <http://docs.oracle.com/javase/7/docs/technotes/tools/linux/jdkfiles.html>
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-09-02 20:01 -0400 |
| Message-ID | <k20ruj$rmc$1@dont-email.me> |
| In reply to | #2070 |
On 09/02/2012 06:39 PM, Redcat wrote: > 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. > This may help. <http://docs.oracle.com/javase/7/docs/technotes/guides/extensions/index.html>
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-09-02 20:08 -0400 |
| Message-ID | <k20sd3$tos$1@dont-email.me> |
| In reply to | #2072 |
On 09/02/2012 08:01 PM, Jeff Higgins wrote: > On 09/02/2012 06:39 PM, Redcat wrote: > >> 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. >> > This may help. > <http://docs.oracle.com/javase/7/docs/technotes/guides/extensions/index.html> > You might read the Extensions Tutorial here: <http://docs.oracle.com/javase/tutorial/ext/> Others here might ask you to pay particular attention to the first three paragraphs.
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-09-04 03:13 -0700 |
| Message-ID | <k24k8i$mtm$2@news.albasani.net> |
| In reply to | #2073 |
Jeff Higgins wrote:
> Jeff Higgins wrote:
>> Redcat wrote:
>>> 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.
>>>
>> This may help.
>> <http://docs.oracle.com/javase/7/docs/technotes/guides/extensions/index.html>
>>
> You might read the Extensions Tutorial here:
> <http://docs.oracle.com/javase/tutorial/ext/>
> Others here might ask you to pay particular attention to the first three
> paragraphs.
Don't use extensions.
The OP just needs to add a library, not change the configuration of Java itself.
Follow Jeff's advice about the "How to set classpath" links.
But eschew the CLASSPATH envar in favor of the "-classpath" ("-cp") tool option.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-09-02 18:04 -0700 |
| Message-ID | <k20vm6$clt$1@dont-email.me> |
| In reply to | #2070 |
On 9/2/2012 3:39 PM, Redcat wrote:
> 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.
This seems wrong. In general those should point to your JDK
installation, not glassfish. I see you're using a jdk7 directory,
however this feel off as well. I normally separate the container and
the JDK into two distinct directory hierarchies.
Not saying this could never work, but it seems odd and might have some
hidden gotchas.
> 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.
Most Java development doesn't use the environment variables you mention.
I think ant uses JAVAHOME, but that's about it.
What are you using now for development, before things go off the rails?
>
> 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;
This seems like a bad idea, declaring your code to be a part of the
org.apache package space.
>
> import org.apache.http.HttpEntity;
>
> 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;
OK, I think I see. javac doesn't like your class path. The first thing
is that you'll need "." mostly likely in the path. The second is that
most of us use an IDE or at least ant to do builds, and don't rely on
class paths. What happens when you have two or more similar libraries
with name collisions?
Class path is a quickie convenience tool for doing local development. I
wouldn't be trying to configure it to point to your glassfish
installation. Seems like something's bound to cause problems.
Also, can you please get the library that you copied into ../lib, and
verify it has the symbols listed here (the ones javac can't find).
That's a shot in the dark but "linked to wrong lib" is the oldest user
error in the book.
>
> 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.
Again, without a pointer you your code base ("." or something similar)
something is bound to be messed up. My advice would be to learn the
command line tools with a simple "hello world" program. Then for JEE
development get a decent IDE. You do not want to be trying to configure
all that junk yourself.
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-09-04 03:17 -0700 |
| Message-ID | <k24kg1$o3p$1@news.albasani.net> |
| In reply to | #2075 |
markspace wrote: > Redcat wrote: >> 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. > > This seems wrong. In general those should point to your JDK installation, not > glassfish. I see you're using a jdk7 directory, however this feel off as > well. I normally separate the container and the JDK into two distinct > directory hierarchies. > > Not saying this could never work, but it seems odd and might have some hidden > gotchas. Libraries belong each in their own directory or JAR. >> 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; > > This seems like a bad idea, declaring your code to be a part of the org.apache > package space. Indeed! And such hubris, too! >> import org.apache.http.HttpEntity; >> >> 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; Because you didn't include the *JAR* in your classpath, but a directory. > OK, I think I see. javac doesn't like your class path. The first thing is > that you'll need "." mostly likely in the path. The second is that most of us > use an IDE or at least ant to do builds, and don't rely on class paths. What > happens when you have two or more similar libraries with name collisions? The OP said they used "blah-blah/lib" in the classpath. That wouldn't work for JARs; they'd need "blah-blah/lib/*". -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Date | 2012-09-02 18:32 -0700 |
| Message-ID | <k211av$j6m$1@dont-email.me> |
| In reply to | #2070 |
On 9/2/2012 3:39 PM, Redcat wrote:
> 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?
>
The CLASSPATH, whether the environment variable or the -cp option, must
point to the directory where there are .class files and/or the specific
jar(s) themselves where those .class files reside. Don't forget the
current working directory.
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-09-03 02:07 -0700 |
| Message-ID | <aos84819ue2ih3fes8h2um13ej1v896ov6@4ax.com> |
| In reply to | #2070 |
On 2 Sep 2012 22:39:57 GMT, Redcat <redcat@catfolks.net> wrote, quoted or indirectly quoted someone who said : >I'm obviously missing something. Could anyone point me to what I might be >overlooking? For general background see http://mindprod.com/jgloss/classpath.html Pretty well any complex package requires you to either put jars in a special place, or configure a list of places to look other than the general classpath. -- Roedy Green Canadian Mind Products http://mindprod.com A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. ~ Max Planck 1858-04-23 1947-10-04
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.help
csiph-web