我正在使用我公司的 Ant 脚本来编译一个使用 javax.jms API 的类。即使 ant 脚本显示它正在加载类,它似乎也找不到任何这个 API 类的方法(我确实确认 jms.jar 位于 Ant 构建正在使用的类路径中)。我也在使用 Eclipse,这个类在 Eclipse 中编译得很好(使用与 Ant Build 脚本的类路径中相同的 jms.jar)。我查看了 javax.jms API,在我看来我正在正确编码。下面是代码的摘录,后面是编译输出的摘录。
代码摘录
import java.util.*;
import javax.jms.*;
import javax.naming.*;
import javax.naming.directory.*;
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
environment.put(Context.PROVIDER_URL, "file:C:\\MQ-JNDI");
final InitialDirContext ctx = new InitialDirContext( environment );
final ConnectionFactory factory = (ConnectionFactory)ctx.lookup("PRIMARY_QCF");
final Destination destination = (Destination)ctx.lookup("Q_LIST");
final javax.jms.Connection connection = factory.createConnection();
connection.start();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = session.createProducer(destination);
ObjectMessage message = session.createObjectMessage(msg);
producer.send(message);
ANT BUILD 结果的摘录
[javac] [loading javax\naming\Context.class(javax\naming:Context.class)]
[javac] [loading javax\naming\directory\InitialDirContext.class(javax\naming\directory:InitialDirContext.class)]
[javac] [loading javax\jms\ConnectionFactory.class(javax\jms:ConnectionFactory.class)]
[javac] [loading javax\naming\Name.class(javax\naming:Name.class)]
[javac] [loading javax\jms\Destination.class(javax\jms:Destination.class)]
[javac] [loading javax\jms\Connection.class(javax\jms:Connection.class)]
[javac] C:\work\tla\ja11\projects\common\src\com\ntrs\tla\controller\MemberListController.java:1474: cannot find symbol
[javac] symbol : method createConnection()
[javac] location: interface javax.jms.ConnectionFactory
[javac] final javax.jms.Connection connection = factory.createConnection();
[javac] ^
[javac] [loading javax\jms\Session.class(javax\jms:Session.class)]
[javac] C:\work\tla\ja11\projects\common\src\com\ntrs\tla\controller\MemberListController.java:1479: cannot find symbol
[javac] symbol : method createSession(boolean,int)
[javac] location: interface javax.jms.Connection
[javac] final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
[javac] ^
[javac] [loading javax\jms\MessageProducer.class(javax\jms:MessageProducer.class)]
[javac] C:\work\tla\ja11\projects\common\src\com\ntrs\tla\controller\MemberListController.java:1483: cannot find symbol
[javac] symbol : method createProducer(javax.jms.Destination)
[javac] location: interface javax.jms.Session
[javac] final MessageProducer producer = session.createProducer(destination);
[javac] ^
[javac] [loading javax\jms\ObjectMessage.class(javax\jms:ObjectMessage.class)]
[javac] C:\work\tla\ja11\projects\common\src\com\ntrs\tla\controller\MemberListController.java:1486: cannot find symbol
[javac] symbol : method send(javax.jms.ObjectMessage)
[javac] location: interface javax.jms.MessageProducer
[javac] producer.send(message);