2014-11-18 1 views
2

jboss가있는 Java 크롤러에서 앱을 개발 중입니다. 나는 다음과 같은 코드를 만들어 :InitialContext jboss의 예외

connectionFactoryLookupAddress = new String("jms/RemoteConnectionFactory"); 
destinationLookupAddress = new String("jms/topic/mC"); 
environment = new Properties(); 
environment.put(Context.SECURITY_PRINCIPAL, "isuser"); 
environment.put(Context.SECURITY_CREDENTIALS, "is"); 
environment.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory"); 
environment.put(Context.PROVIDER_URL, "remote://localhost:4447"); 
InitialContext iCtx = new InitialContext(environment); 

을 그리고 난 ...

javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory] 
(...) 
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory 
(...) 

가 이미 JBoss에 client.jar가, 아무것도를 추가 한 다음 예외가이 칠은 JBoss 서버를 구성해야 프로젝트를 만들거나 서버에 사용자를 추가 하시겠습니까? 나는 이클립스를 사용하고있다. 이 주제에 관한 글을 읽었지만 jboss 설정으로이 코드를 실행해야하는지 확실하지 않았습니다. 도움이 되었습니까?

답변

1

// Set up all the default values 
    private static final String DEFAULT_MESSAGE = "Hello, World!"; 
    private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory"; 
    //private static final String DEFAULT_DESTINATION = "paymentNotification"; 
    private static final String DEFAULT_DESTINATION = "myTopic"; 
    private static final String DEFAULT_MESSAGE_COUNT = "5"; 
    private static final String DEFAULT_USERNAME = "jms"; 
    private static final String DEFAULT_PASSWORD = "jms"; 
    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory"; 
    private static final String PROVIDER_URL = "http-remoting://127.0.0.1:8080"; 
//https://github.com/wildfly/quickstart/tree/master/helloworld-jms 
    public static void main(String[] args) { 

     Context namingContext = null; 

     try { 
      String userName = DEFAULT_USERNAME; 
      String password = DEFAULT_PASSWORD; 

      // Set up the namingContext for the JNDI lookup 
      final Properties env = new Properties(); 
      env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); 
      env.put(Context.PROVIDER_URL, PROVIDER_URL); 
      env.put(Context.SECURITY_PRINCIPAL, userName); 
      env.put(Context.SECURITY_CREDENTIALS, password); 
      namingContext = new InitialContext(env); 

      // Perform the JNDI lookups 
      String connectionFactoryString =DEFAULT_CONNECTION_FACTORY; 
      System.out.println("@@Attempting to acquire connection factory \"" + connectionFactoryString + "\""); 
      ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString); 
      System.out.println("@@@Found connection factory \"" + connectionFactoryString + "\" in JNDI " +connectionFactory.toString()); 

      String destinationString = System.getProperty("destination", DEFAULT_DESTINATION); 
      System.out.println("@@Attempting to acquire destination \"" + destinationString + "\""); 
      Destination destination = (Destination) namingContext.lookup(destinationString); 
      System.out.println("@@@Found destination \"" + destinationString + "\" in JNDI"); 

      int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT)); 
      String content = DEFAULT_MESSAGE; 

      try (JMSContext context = connectionFactory.createContext(userName, password)) { 
       System.out.println("###Sending " + count + " messages with content: " + content); 
       // Send the specified number of messages 


       for (int i = 0; i < count; i++) { 
        context.createProducer().send(destination, content); 
       } 

는 또한 구성-full.xml에서 JMS 주제를 구성하는 작업을해야한다 Link