aspose file tools*
The moose likes Beginning Java and the fly likes ClassPath Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ClassPath Problem" Watch "ClassPath Problem" New topic
Author

ClassPath Problem

dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi All,

I am facing a peculiar problem atleast in my perspective:

I have set my classpath correctly and i am able to compile all the files and get the output.
But consistently the compiler fails to compile the following code:


import java.io.*;
import java.net.*;

public class MailSender {
public static void main(String[] args) {
try {
Socket s = new Socket("smtp.mail.yahoo.com",25);
Authenticator authenticator = new ProxyAuthenticator();
Authenticator.setDefault(authenticator);
PrintWriter out = new PrintWriter(s.getOutputStream());
out.println("HELO sending host");
out.println("MAIL FROM: sivadinesh7@yahoo.co.in");
out.println("RCPT TO: sivadinesh.java@gmail.com");
out.println("DATA");
out.println("Hi how are you");
out.println("QUIT");
}catch(Exception e) {
e.printStackTrace();
}
}
}

import java.net.*;
class ProxyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxxxxx","xxxxxx".toCharArray());
}
}


If i copy the source files into the "bin" directory of the Jdk it works fine.
Thanks in advance!!!
dinesh
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
whats the error and classpath entries?
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
This is the error i am getting


MailSender.java:9: cannot find symbol
symbol : method setDefault(Authenticator)
location: class Authenticator
Authenticator.setDefault(authenticator);
^
1 error
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
you need to add mail.jar (javamail library) on the classpath while compiling
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Thanks Ajay,

But i have one doubt how it works fine while compiling from the jdk bin directory?

Again thanks,
dinesh.
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
what do you have in jdk bin folder? I mean can you post the jar files of jdk bin folder
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
I dont have any jar files in my jdk/bin folder.
This behavior is very consistent. When ever i try compiling the same file in different locations i am getting the compilation error. Where as, while compiling from inside the jdk / bin it just works fine.
Paul Codillo
Ranch Hand

Joined: Aug 21, 2002
Posts: 38
Can you post the command you issued in compiling your class? Or could you post your classpath as well? It would be helpful if we see how you defined your classpath.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
I issued the following command:

javac MailSender.java

My ClassPath:

JAVA_HOME=C:\Program Files\Java\jdk1.5.0_07
PATH=%JAVA_HOME%\bin;
CLASSPATH=.;%JAVA_HOME%\lib\tools.jar;

Thanks for your efforts!!!
dinesh.
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
can you post the result of these also,

javac -version
echo %CLASSPATH%
Paul Codillo
Ranch Hand

Joined: Aug 21, 2002
Posts: 38
Are you getting the errors for java.net.Authenticator class only? It's found in rt.jar, make sure it's in your classpath.
Paul Codillo
Ranch Hand

Joined: Aug 21, 2002
Posts: 38
Try removing your CLASSPATH definition. Just maintain the JAVA_HOME and include it in the PATH. Let me know if that works.

Good luck!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

The reason that you get different behavior in the JDK/bin directory is likely that when your current directory is JDK/bin, you're using one JDK, and when it's anything else, you're using another. Try "javac -J-version" when your current directory is in the JDK/bin directory, and when it's somewhere else, and see if they match.


[Jess in Action][AskingGoodQuestions]
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Ajay,


The output of "javac -verbose MailSender.java"

[parsing started MailSender.java]
[parsing completed 150ms]
[search path for source files: [., C:\Program Files\Java\jdk1.5.0_07\LIB\TOOLS.J
AR, C:\Tomcat\LIB\servlet-api.jar, C:/struts\lib\struts.jar, C:\struts\lib\commo
ns-beanutils.jar, C:\struts\lib\commons-digester.jar, C:\struts\lib\commons-file
upload.jar, C:\struts\lib\commons-logging.jar, C:\struts\lib\commons-validator.j
ar, C:\struts\lib\jakarta-oro.jar, c:\Ant\lib\ant.jar, C:\JUnit\junit4.1\junit4.
1\junit-4.1.jar]]
[search path for class files: [C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar,
C:\Program Files\Java\jdk1.5.0_07\jre\lib\jsse.jar, C:\Program Files\Java\jdk1.
5.0_07\jre\lib\jce.jar, C:\Program Files\Java\jdk1.5.0_07\jre\lib\charsets.jar,
C:\Program Files\Java\jdk1.5.0_07\jre\lib\ext\dnsns.jar, C:\Program Files\Java\j
dk1.5.0_07\jre\lib\ext\localedata.jar, C:\Program Files\Java\jdk1.5.0_07\jre\lib
\ext\sunjce_provider.jar, C:\Program Files\Java\jdk1.5.0_07\jre\lib\ext\sunpkcs1
1.jar, ., C:\Program Files\Java\jdk1.5.0_07\LIB\TOOLS.JAR, C:\Tomcat\LIB\servlet
-api.jar, C:/struts\lib\struts.jar, C:\struts\lib\commons-beanutils.jar, C:\stru
ts\lib\commons-digester.jar, C:\struts\lib\commons-fileupload.jar, C:\struts\lib
\commons-logging.jar, C:\struts\lib\commons-validator.jar, C:\struts\lib\jakarta
-oro.jar, c:\Ant\lib\ant.jar, C:\JUnit\junit4.1\junit4.1\junit-4.1.jar]]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/lang/Object.class
)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/lang/String.class
)]
[checking MailSender]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/net/Socket.class)
]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/net/SocketAddress
.class)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/net/InetAddress.c
lass)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/net/SocketImpl.cl
ass)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/net/Proxy.class)]

[loading .\Authenticator.class]
[loading .\ProxyAuthenticator.class]
[loading C:\Tomcat\LIB\servlet-api.jar(javax/servlet/http/HttpServlet.class)]
[loading C:\Tomcat\LIB\servlet-api.jar(javax/servlet/GenericServlet.class)]
MailSender.java:9: cannot find symbol
symbol : method setDefault(Authenticator)
location: class Authenticator
Authenticator.setDefault(authenticator);
^
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/io/PrintWriter.cl
ass)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/io/OutputStream.c
lass)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/io/File.class)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/io/Writer.class)]

[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/lang/Exception.cl
ass)]
[loading C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar(java/lang/Throwable.cl
ass)]
[total 1802ms]
1 error


Output of echo


.;C:\Program Files\Java\jdk1.5.0_07\LIB\TOOLS.JAR;.;C:\Tomcat\LIB\servlet-api.ja
r;.;C:/struts\lib\struts.jar;.;c:\Ant\lib\ant.jar;.;C:\JUnit\junit4.1\junit4.1\j
unit-4.1.jar;.;C:\Program Files\Java\jdk1.5.0_07\jre\lib\rt.jar;

Again thanks for your continuous efforts.

regards,
dinesh.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Ernest,

It works fine while using the command you gave (javac -J-verbose MailSender.java) Could you please explain about this? I am able to compile from anywhere using your command.

Thank you very much!!!
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182

[loading .\Authenticator.class]
[loading .\ProxyAuthenticator.class]

sounds like it found something on the present working directory.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Ajay,

You are Great!!!

Thats correct. I have already built a class called Authenticator. So while referring it has been considered instead of the library class i needed.

Thanks for your continuous support.

regards,
dinesh.
 
wood burning stoves
 
subject: ClassPath Problem
 
Similar Threads
Proxy again...Authentication problem...
Sockets vs URL Based classes
Need Help in Netowork Programming.
Webservice Socket closed exception
isMailSent()