[JMS] dziwny error

0

Witam

Chcialem przetestowac pewien przyklad z ksiazki Java Message Services 2nd.
Niestety nie moge uruchomic tego przykladu. Dostaje nastepujacy wyjatek:

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/jms/JMSException
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: jns_testApplication.Chat.  Program will exit.
Exception in thread "main" Java Result: 1

Jest jakis problem z metoda onMessage, bo jesli ja zakomentuje i wyrzuce implementowanie interfejsu MessageListener, a w metodzie main zostawie tylko:

if (args.length!=3)
//                System.out.println("Factory, Topic, or username missing");

To sie kompiluje i uruchamia bez bledow.

Kod:

package jns_testApplication;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicPublisher;
import javax.jms.TopicSession;
import javax.jms.TopicSubscriber;

import javax.naming.*;

public class Chat implements MessageListener{
//    private TopicSession pubSession;
//    private TopicPublisher publisher;
//    private TopicConnection connection;
//    private String username;
//
//    /* Constructor used to Initialize Chat */
//    public Chat(String topicFactory, String topicName, String username)
//        throws Exception {
//
//    	// Obtain a JNDI connection using the jndi.properties file
//        InitialContext ctx = new InitialContext();
//
//        // Look up a JMS connection factory
//        TopicConnectionFactory conFactory =
//        	(TopicConnectionFactory)ctx.lookup(topicFactory);
//
//        // Create a JMS connection
//        TopicConnection connection = conFactory.createTopicConnection();
//
//        // Create two JMS session objects
//        TopicSession pubSession = connection.createTopicSession(
//        	false, Session.AUTO_ACKNOWLEDGE);
//        TopicSession subSession = connection.createTopicSession(
//        	false, Session.AUTO_ACKNOWLEDGE);
//
//        // Look up a JMS topic
//        Topic chatTopic = (Topic)ctx.lookup(topicName);
//
//        // Create a JMS publisher and subscriber
//        TopicPublisher publisher =
//            pubSession.createPublisher(chatTopic);
//        TopicSubscriber subscriber =
//            subSession.createSubscriber(chatTopic, null, true);
//
//        // Set a JMS message listener
//        subscriber.setMessageListener(this);
//
//        // Intialize the Chat application variables
//        this.connection = connection;
//        this.pubSession = pubSession;
//        this.publisher = publisher;
//        this.username = username;
//
//        // Start the JMS connection; allows messages to be delivered
//        connection.start( );
//    }
//
    /* Receive Messages From Topic Subscriber */
    public void onMessage(Message message) {

            TextMessage textMessage = (TextMessage) message;
            String text = null;
        try {
            text = textMessage.getText();
        } catch (JMSException ex) {
            Logger.getLogger(Chat.class.getName()).log(Level.SEVERE, null, ex);
        }
            System.out.println(text);

    }
//
//    /* Create and Send Message Using Publisher */
//    protected void writeMessage(String text) throws JMSException {
//        TextMessage message = pubSession.createTextMessage( );
//        message.setText(username+": "+text);
//        publisher.publish(message);
//    }
//
//    /* Close the JMS Connection */
//    public void close( ) throws JMSException {
//        connection.close( );
//    }

    /* Run the Chat Client */
    public static void main(String [] args){
                    if (args.length!=3)
                System.out.println("Factory, Topic, or username missing");

//        try{
//            if (args.length!=3)
//                System.out.println("Factory, Topic, or username missing");
//
//            // args[0]=topicFactory; args[1]=topicName; args[2]=username
//            Chat chat = new Chat(args[0],args[1],args[2]);
//
//            // Read from command line
//            BufferedReader commandLine = new
//              java.io.BufferedReader(new InputStreamReader(System.in));
//
//            // Loop until the word "exit" is typed
//            while(true){
//                String s = commandLine.readLine( );
//                if (s.equalsIgnoreCase("exit")){
//                    chat.close( ); // close down connection
//                    System.exit(0);// exit program
//                } else
//                    chat.writeMessage(s);
//            }
//        } catch (Exception e){ e.printStackTrace( ); }
    }
}

Plik jndi.properties:

# To change this template, choose Tools | Templates
# and open the template in the editor.

#java.naming.provider.url=tcp://192.168.1.3:3035
#java.naming.factory.initial=org.exolab.jms.jndi.InitialContextFactory
#java.naming.security.principal=admin
#java.naming.security.credentials=openjms

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:61616
java.naming.security.principal=system
java.naming.security.credentials=manager
connectionFactoryNames = TopicCF
#connection.QueueCF.brokerURL = tcp://localhost:61616
#queue.queue1 = jms.queue1
topic.topic1 = jms.topic1


#connection.localConnectionFactory.userName = system
#connection.localConnectionFactory.password = manager

Projekt w NetBeans 6.9.
Biblioteki: Java EE API libary, activemq-all-5.3.2.jar

Nie mam zielonego pojecia o co chodzi. Moze ktos sie orientuje jak to naprawic?

0

Nie potrzebnie zaladowalem biblioteke Java EE. W active....jar znajduje sie wszystko co potrzeba.

1 użytkowników online, w tym zalogowanych: 0, gości: 1