I felt i had to post the solution to this kind of problem on this blog after spending some time in figuring it out.
I was working through an example of the jms stuff when i encountered the error below which had to my import line:

import javax.jms.*;

C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:4: package javax.jms does not exist
import javax.jms.*;
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:18: cannot find symbol
symbol  : class QueueConnectionFactory
location: class com.tunji.jms.SimpleQueueSender
QueueConnectionFactory  queueConnectionFactory = null;
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:19: cannot find symbol
symbol  : class QueueConnection
location: class com.tunji.jms.SimpleQueueSender
QueueConnection         queueConnection = null;
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:20: cannot find symbol
symbol  : class QueueSession
location: class com.tunji.jms.SimpleQueueSender
QueueSession            queueSession = null;
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:21: cannot find symbol
symbol  : class Queue
location: class com.tunji.jms.SimpleQueueSender
Queue                   queue = null;
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:22: cannot find symbol
symbol  : class QueueSender
location: class com.tunji.jms.SimpleQueueSender
QueueSender             queueSender = null;
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:23: cannot find symbol
symbol  : class TextMessage
location: class com.tunji.jms.SimpleQueueSender
TextMessage             message = null;
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:56: cannot find symbol
symbol  : class QueueConnectionFactory
location: class com.tunji.jms.SimpleQueueSender
queueConnectionFactory = (QueueConnectionFactory)
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:58: cannot find symbol
symbol  : class Queue
location: class com.tunji.jms.SimpleQueueSender
queue = (Queue) jndiContext.lookup(queueName);
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:79: cannot find symbol
symbol  : variable Session
location: class com.tunji.jms.SimpleQueueSender
Session.AUTO_ACKNOWLEDGE);
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:94: cannot find symbol
symbol  : class JMSException
location: class com.tunji.jms.SimpleQueueSender
} catch (JMSException e) {
^
C:\Utilities\Textpad programs\com\tunji\jms\SimpleQueueSender.java:101: cannot find symbol
symbol  : class JMSException
location: class com.tunji.jms.SimpleQueueSender
} catch (JMSException e) {}
^
12 errors

Tool completed with exit code 1

All i did to get this problem solved was to go to where i downloaded the j2ee sdk to and included the path
to j2ee.jar in my class path in the system variables section as below

C:\Utilities\Textpad programs\com\tunji\jms\j2ee.jar;

Advertisements

12 thoughts on “How i resolved Java jms error javax.jms

  1. Hi adetunjiadegbite,

    do you have any idea about this below error,

    i am using bea weblogic 8.1 version and i am getting this below in my app server,

    Like

      1. hi adetunjiadegbite, i have an exercise about Message Queueing System using openjms.but i don’t know about it. can you share any project? thank you very much!

        Like

  2. D:\Raju\workplace\JMSProject\src>javac JMSMessageSender.java
    JMSMessageSender.java:5: package javax.jms does not exist
    import javax.jms.Connection;
    ^
    JMSMessageSender.java:6: package javax.jms does not exist
    import javax.jms.ConnectionFactory;
    ^
    JMSMessageSender.java:7: package javax.jms does not exist
    import javax.jms.Message;
    ^
    JMSMessageSender.java:8: package javax.jms does not exist
    import javax.jms.MessageConsumer;
    ^
    JMSMessageSender.java:9: package javax.jms does not exist
    import javax.jms.MessageProducer;
    ^
    JMSMessageSender.java:10: package javax.jms does not exist
    import javax.jms.Queue;
    ^
    JMSMessageSender.java:11: package javax.jms does not exist
    import javax.jms.Session;
    ^
    JMSMessageSender.java:12: package javax.jms does not exist
    import javax.jms.TextMessage;
    ^
    JMSMessageSender.java:16: package org.apache.log4j does not exist
    import org.apache.log4j.Logger;
    ^
    JMSMessageSender.java:28: cannot find symbol
    symbol : class Logger
    location: class com.sample.JMSMessageSender
    Logger log = Logger.getLogger(com.sample.JMSMessageSender.class.getName());
    ^
    JMSMessageSender.java:28: cannot find symbol
    symbol : variable Logger
    location: class com.sample.JMSMessageSender
    Logger log = Logger.getLogger(com.sample.JMSMessageSender.class.getName());
    ^
    JMSMessageSender.java:45: cannot find symbol
    symbol : class ConnectionFactory
    location: class com.sample.JMSMessageSender
    ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(“ConnectionFactory”);
    ^
    JMSMessageSender.java:45: cannot find symbol
    symbol : class ConnectionFactory
    location: class com.sample.JMSMessageSender
    ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(“ConnectionFactory”);
    ^
    JMSMessageSender.java:47: package javax.jms does not exist
    Queue queue = (javax.jms.Queue)ctx.lookup(“queue/queueA”);
    ^
    JMSMessageSender.java:49: cannot find symbol
    symbol : class Connection
    location: class com.sample.JMSMessageSender
    Connection connection = connectionFactory.createConnection();
    ^
    JMSMessageSender.java:56: cannot find symbol
    symbol : class Session
    location: class com.sample.JMSMessageSender
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ^
    JMSMessageSender.java:56: cannot find symbol
    symbol : variable Session
    location: class com.sample.JMSMessageSender
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ^
    JMSMessageSender.java:58: cannot find symbol
    symbol : class MessageProducer
    location: class com.sample.JMSMessageSender
    MessageProducer messageProducer = session.createProducer(queue);
    ^
    JMSMessageSender.java:60: cannot find symbol
    symbol : class TextMessage
    location: class com.sample.JMSMessageSender
    TextMessage textMessage = session.createTextMessage();
    ^
    Note: JMSMessageSender.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    19 errors

    I downloaded the j2ee jar file and set the path but still getting error

    Like

  3. I am using Jboss6.10 version and JDK1.6.
    While complilng my code I am getting these above 19 error.
    I downloaded the j2ee jar file and set the path but still getting error.
    Can any body plase help on this.

    MY JAVA code is as below:
    ————————

    package com.sample;

    import java.util.Hashtable;

    import javax.jms.Connection;
    import javax.jms.ConnectionFactory;
    import javax.jms.Message;
    import javax.jms.MessageConsumer;
    import javax.jms.MessageProducer;
    import javax.jms.Queue;
    import javax.jms.Session;
    import javax.jms.TextMessage;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import org.apache.log4j.Logger;
    import java.io.*;
    import java.sql.SQLException;
    import java.util.*;

    public class JMSMessageSender {

    public static void main(String[] args) {

    try {
    // Enable the Log4J
    Logger log = Logger.getLogger(com.sample.JMSMessageSender.class.getName());

    /*
    * Connecting to JBoss naming service running on local host and on
    * default port 1099 the environment that should be created is like the
    * one shown below :172.20.37.237
    */

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, “org.jnp.interfaces.NamingContextFactory”);
    env.put(Context.PROVIDER_URL, “jnp://localhost:1099”);
    env.put(Context.URL_PKG_PREFIXES, “org.jboss.naming:org.jnp.interfaces”);

    // Create the initial context
    Context ctx = new InitialContext(env);
    // Lookup the JMS connection factory from the JBoss 5.1 object store
    ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(“ConnectionFactory”);
    // Lookup a queue from the JBoss 5.1 object store
    Queue queue = (javax.jms.Queue)ctx.lookup(“queue/queueA”);
    // Create a connection to the JBoss 5.1 Message Service
    Connection connection = connectionFactory.createConnection();
    //Date format
    java.text.DateFormat dtformat = new java.text.SimpleDateFormat(“yyyy-MM-dd HH:mm:ss:S”);

    //Push number of messages in to the queue
    for (int i=0;i<=2500;i++) {
    // Create a session within the connection
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create a message producer to put messages on the queue
    MessageProducer messageProducer = session.createProducer(queue);
    //Create and send a message to the queue
    TextMessage textMessage = session.createTextMessage();
    //Passing new value for each message A0…A99
    String msgId = "ID:"+i;
    String message ="”+msgId+”Name”+msgId+””;
    // textMessage.setJMSMessageID(msgId);
    textMessage.setText(message);
    textMessage.setJMSCorrelationID(msgId);
    messageProducer.send(textMessage);
    // System.out.println(“Sending Message Id: ” + textMessage.getJMSMessageID());
    Date date = new Date();
    String dateTime = dtformat.format(date);
    log.info(“Message Id: “+msgId+ ” Sent Time: “+ dateTime);
    //System.out.println(“Message Id: “+msgId+ “Sent Time: “+ dateTime);
    //Close the session and connection resources.
    session.close();
    }
    connection.close();

    } catch (Exception ex) {ex.printStackTrace(); }
    }

    }

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s