Я работаю над созданием проекта с помощью службы jms. Я создал проект в eclipse.Не удалось скомпилировать проект java даже после добавления файла jar?
Project name : JmsTest
src->jmstestclient(package)->SimpleProducer.java(class)
Код для SimpleProducer.java выглядит следующим образом
import javax.jms.*;
import javax.naming.*;
public class SimpleSynchConsumer {
/**
* Main method.
*
* @param args the destination name and type used by the
* example
*/
public static void main(String[] args) {
String destName = null;
Context jndiContext = null;
ConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
Destination dest = null;
MessageConsumer consumer = null;
TextMessage message = null;
if (args.length != 1) {
System.out.println("Program takes one argument: <dest_name>");
System.exit(1);
}
destName = new String(args[0]);
System.out.println("Destination name is " + destName);
/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
jndiContext = new InitialContext();
} catch (NamingException e) {
System.out.println("Could not create JNDI API context: " +
e.toString());
System.exit(1);
}
/*
* Look up connection factory and destination. If either
* does not exist, exit. If you look up a
* TopicConnectionFactory or a QueueConnectionFactory,
* program behavior is the same.
*/
try {
connectionFactory = (ConnectionFactory) jndiContext.lookup(
"jms/ConnectionFactory");
dest = (Destination) jndiContext.lookup(destName);
} catch (Exception e) {
System.out.println("JNDI API lookup failed: " + e.toString());
System.exit(1);
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create consumer, then start message delivery.
* Receive all text messages from destination until
* a non-text message is received indicating end of
* message stream.
* Close connection.
*/
try {
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(dest);
connection.start();
while (true) {
Message m = consumer.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println("Reading message: " +
message.getText());
} else {
break;
}
}
}
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
}
}
}
}
}
Я скачал файл фляги javax.jms-3.1.2.2 и поместил этот файл в BIN \ Lib в папке Java. Но я получаю следующую ошибку.
The import javax.jms cannot be resolved.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ConnectionFactory cannot be resolved to a type
Connection cannot be resolved to a type
Session cannot be resolved to a type
Destination cannot be resolved to a type
MessageConsumer cannot be resolved to a type
TextMessage cannot be resolved to a type
ConnectionFactory cannot be resolved to a type
Destination cannot be resolved to a type
Session cannot be resolved to a variable
Message cannot be resolved to a type
TextMessage cannot be resolved to a type
TextMessage cannot be resolved to a type
JMSException cannot be resolved to a type
JMSException cannot be resolved to a type
at jmstestclient.SimpleSynchConsumer.main(SimpleSynchConsumer.java:51)
Он указывает ошибку на импорт javax.jms линии
В настоящее время я DONOT есть JEE или j2ee. Я установил только jdk, но не j2ee. Я должен установить j2ee для подключения JMS-сервера.
Как я могу сделать эту программу компилируемой.
Я новичок в затмении. Как я могу определить свой файл jar в пути к классам приложения – Robinhood
@Robinhood следовать этому http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29 – Kick
Thank вы. Мне удалось собрать файл jar, и код был скомпилирован. Не могли бы вы предложить мне, как запустить приведенный выше код для подключения к серверу JMS. Мне нужно установить j2EE, и приведенный выше код подключит меня к серверу JMS. – Robinhood