cancel
Showing results for 
Search instead for 
Did you mean: 

How to develop JMS Java Application.

Former Member
0 Kudos

Now,I develop Java Application(J2SE stand alone) to send JMS for JMS Adapter(sender) verification.

But fatal exception is displayed when I execute Java application.

Error is rellated to following code.

InitialContext context = new InitialContext(properties); //←(SendJMS.java:41)

Are there wrong points in this code or other necessary settings(for example on Visual administrator) ?

I think that Java Appli can send Java Message to JMS provider in J2EE(XIserver) by using JNDI.

Is my thougt wrong?

Sorry poor English.

Best regards.

-


(Java code)

/*

  • Created on 2007/09/06

*

  • To change the template for this generated file go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

package jmsPackageS;

import java.util.Properties;

import javax.naming.*;

import javax.jms.*;

/**

  • @author sakurai.youkou

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class SendJMS {

public static void main(String[] args) {

try {

//1.JNDI server connection

//JNDI server connection property settings

java.util.Properties properties = new Properties();

properties.put(

Context.INITIAL_CONTEXT_FACTORY,

"com.sap.engine.services.jndi.InitialContextFactoryImpl");

//JNDI server URL

properties.put(Context.PROVIDER_URL, "xidevelp:50004");

//JNDI login data

//properties.put(Context.SECURITY_PRINCIPAL, "J2EE_ADMIN");

//properties.put(Context.SECURITY_CREDENTIALS, "mypassword");

//start initial context with the properties specified

InitialContext context = new InitialContext(properties); //(SendJMS.java:41)

//2.Register the connection factory

QueueConnectionFactory queueConnectionFactory =

(QueueConnectionFactory) context.lookup(

"jmsfactory/default/QueueConnectionFactory");

//3.Specify the connection type //JMS provider connection

QueueConnection queueConnection =

queueConnectionFactory.createQueueConnection();

//4.Start the connection

//start the connection of Queue type

queueConnection.start();

//5.Create session

//create session of Topic type

QueueSession queueSession =

queueConnection.createQueueSession(

false,

Session.AUTO_ACKNOWLEDGE);

//6.Create or look up a destination

//create destination of Queue type

//Queue queue = queueSession.createQueue("Example_destination_name");

//look up a destination of Queue type

Queue queue =

(Queue) context.lookup("jmsqueues/default/sapDemoQueue");

//7.sender

// create subscriber to a queue

QueueSender queueSender = queueSession.createSender(queue);

//8.Send message contents

TextMessage textMessage = queueSession.createTextMessage();

textMessage.setText("Test");

//send message

queueSender.send(textMessage);

//sending message

String messageText = textMessage.getText();

System.out.println("Send Message text: " + messageText);

//Final.close

//closes the jms queue session

queueSession.close();

//Close the queue connection

queueConnection.close();

} catch (NamingException ne) {

System.out.println("NamingException: " + ne);

} catch (JMSException jmse) {

System.out.println("JMSException: " + jmse);

} catch (Exception e) {

System.out.println("Error");

}

}

}

-


(error message)

java.lang.NoClassDefFoundError: com/sap/exception/IBaseException

at java.lang.ClassLoader.defineClass0(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:539)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)

at java.net.URLClassLoader.access$100(URLClassLoader.java:55)

at java.net.URLClassLoader$1.run(URLClassLoader.java:194)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:187)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:219)

at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:195)

at jmsPackageS.SendJMS.main(SendJMS.java:41)

-


Accepted Solutions (1)

Accepted Solutions (1)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks resolved.

Former Member
0 Kudos

Hi Abhishek Agrahari

Thanks for your help.

I added sapj2eeclient.jar,naming.jar,exception.jar and logging.jar to classpth.

As a result, I successed Java Message to JMS Provider from Stand Alone Java Application!!

Thank you.