java.lang.Object
java.lang.Throwable
java.lang.Exception
javax.naming.NamingException
javax.naming.NoInitialContextException
- All Implemented Interfaces:
- Serializable
- See Also:
- Source Code,
InitialContext
,
InitialDirContext
,
NamingManager.getInitialContext(java.util.Hashtable, ?>)
,
NamingManager.setInitialContextFactoryBuilder(javax.naming.spi.InitialContextFactoryBuilder)
public NoInitialContextException()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1199]Need to specify class name in environment or system property
By zhuqi_cbins { at } hotmail { dot } com on 2005/03/22 05:17:40 Rate
Need to specify class name in environment or system property
[1689]Help :: JMS
By inderlove { at } yahoo { dot } com on 2005/12/23 22:21:06 Rate
import javax.jms.*;
import javax.naming.*;
public class SimpleQueueSender {
public static void main ( String [ ] args ) {
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
TextMessage message = null;
final int NUM_MSGS;
if ( ( args.length < 1 ) || ( args.length > 2 ) ) {
System.out.println ( "Usage: java SimpleQueueSender " +
" < queue-name > [ < number-of-messages > ] " ) ;
System.exit ( 1 ) ;
}
queueName = new String ( args [ 0 ] ) ;
System.out.println ( "Queue name is " + queueName ) ;
if ( args.length == 2 ) {
NUM_MSGS = ( new Integer ( args [ 1 ] ) ) .intValue ( ) ;
} else {
NUM_MSGS = 1;
}
try {
jndiContext = new InitialContext ( ) ;
} catch ( NamingException e ) {
System.out.println ( "Could not create JNDI API " +
"context: " + e.toString ( ) ) ;
System.exit ( 1 ) ;
}
try {
queueConnectionFactory = ( QueueConnectionFactory )
jndiContext.lookup ( "QueueConnectionFactory" ) ;
queue = ( Queue ) jndiContext.lookup ( queueName ) ;
} catch ( NamingException e ) {
System.out.println ( "JNDI API lookup failed: " +
e.toString ( ) ) ;
System.exit ( 1 ) ;
}
try {
queueConnection =
queueConnectionFactory.createQueueConnection ( ) ;
queueSession =
queueConnection.createQueueSession ( false,
Session.AUTO_ACKNOWLEDGE ) ;
queueSender = queueSession.createSender ( queue ) ;
message = queueSession.createTextMessage ( ) ;
for ( int i = 0; i < NUM_MSGS; i++ ) {
message.setText ( "This is message " + ( i + 1 ) ) ;
System.out.println ( "Sending message: " +
message.getText ( ) ) ;
queueSender.send ( message ) ;
}
queueSender.send ( queueSession.createMessage ( ) ) ;
} catch ( JMSException e ) {
System.out.println ( "Exception occurred: " +
e.toString ( ) ) ;
} finally {
if ( queueConnection != null ) {
try {
queueConnection.close ( ) ;
} catch ( JMSException e ) { }
}
}
}
}
public NoInitialContextException(String explanation)
- See Also:
Throwable.getMessage()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples