Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassPath Problem

 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats the error and classpath entries?
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to add mail.jar (javamail library) on the classpath while compiling
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you have in jdk bin folder? I mean can you post the jar files of jdk bin folder
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the result of these also,

javac -version
echo %CLASSPATH%
 
Paul Codillo
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

sounds like it found something on the present working directory.
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic