2

我正在使用我公司的 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);
4

1 回答 1

2

看起来您的编译器类路径中有 JMS jar 的旧版本(1.0.x),而不是 1.1 版本,或者在 1.1 版本之前。编译器抱怨的方法是 JMS 1.1 引入的方法。

我会仔细查看您传递给<javac>任务的类路径,以找出旧 JAR 的来源并排除它。

于 2012-09-16T18:02:42.033 回答