gpt4 book ai didi

java - 即使加载了所需的 javax.jms 类,ant build (javac) 也会出现 "cannot find symbol"错误

转载 作者:行者123 更新时间:2023-11-30 09:32:52 25 4
gpt4 key购买 nike

我正在使用我公司的 Ant 脚本来编译一个使用 javax.jms API 的类。它似乎无法找到任何此 API 类的方法,即使 ant 脚本显示它正在加载该类(并且我确实确认 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);

最佳答案

您的编译器类路径中似乎有旧版本 (1.0.x) 的 JMS jar,而不是 1.1 版本或位于 1.1 版本之前。编译器提示的方法是 JMS 1.1 中引入的方法。

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

关于java - 即使加载了所需的 javax.jms 类,ant build (javac) 也会出现 "cannot find symbol"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12447600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com