2016-09-30 2 views
0

Ich bin ein einfaches Problem, vor und nach Hilfe suchen.javax.naming.NoInitialContextException: Kann nicht Klasse instanziiert: orj.jboss.naming.remote.client.InitialContextFactory

Hier ist die Ausnahmemeldung:

javax.naming.NoInitialContextException: Cannot instantiate class: orj.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: orj.jboss.naming.remote.client.InitialContextFactory] 
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) 
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) 
    at javax.naming.InitialContext.init(Unknown Source) 
    at javax.naming.InitialContext.<init>(Unknown Source) 
    at ReceveurJMS.<init>(ReceveurJMS.java:44) 
    at ReceveurJMS.main(ReceveurJMS.java:91) 
Caused by: java.lang.ClassNotFoundException: orj.jboss.naming.remote.client.InitialContextFactory 
    at java.net.URLClassLoader.findClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source) 
    at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source) 
    ... 6 more 

Hier ist meine Klasse PanelPhoto:

import java.awt.Graphics; 
import java.awt.image.BufferedImage; 

import javax.swing.JPanel; 

public class PanelPhoto extends JPanel{ 
    private BufferedImage bufferedImage; 

    public void paint(Graphics g){ 
     g.drawImage(bufferedImage, 0, 0, this.getWidth(),this.getHeight(),null); 
    } 

    public BufferedImage getBufferedImage() { 
     return bufferedImage; 
    } 

    public void setBufferedImage(BufferedImage bufferedImage) { 
     this.bufferedImage = bufferedImage; 
    } 

} 

Hier ist meine Klasse EnvoyeurPhoto:

public class EnvoyeurPhoto extends JFrame { 

    private JLabel jLabelPhoto = new JLabel("Photo"); 
    private JComboBox<String> jComboBoxPhotos; 
    private JButton jButtonEnvoyer = new JButton("Envoyer"); 
    private PanelPhoto panelPhoto = new PanelPhoto(); 
    private Connection conn; 
    private Destination destination; 

    public EnvoyeurPhoto() { 
     this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
     this.setLayout(new BorderLayout()); 
     JPanel jPanelN = new JPanel(); 
     File f = new File("photos"); 
     String[] photos = f.list(); 
     jComboBoxPhotos = new JComboBox<String>(photos); 
     jPanelN.setLayout(new FlowLayout()); 
     jPanelN.add(jLabelPhoto); 
     jPanelN.add(jComboBoxPhotos); 
     jPanelN.add(jButtonEnvoyer); 
     this.add(jPanelN, BorderLayout.NORTH); 
     this.add(panelPhoto, BorderLayout.CENTER); 
     this.setBounds(10, 10, 400, 300); 
     this.setVisible(true); 

     init(); 
     jComboBoxPhotos.addActionListener(new ActionListener() { 

      @Override 
      public void actionPerformed(ActionEvent e) { 
       try { 
        String photo = (String) jComboBoxPhotos.getSelectedItem(); 
        File file = new File("photos/" + photo); 
        BufferedImage bi = ImageIO.read(file); 
        panelPhoto.setBufferedImage(bi); 
        panelPhoto.repaint(); 
       } catch (IOException e1) { 
        // TODO Auto-generated catch block 
        e1.printStackTrace(); 
       } 

      } 
     }); 
     jButtonEnvoyer.addActionListener(new ActionListener() { 

      @Override 
      public void actionPerformed(ActionEvent arg0) { 

       try { 
        Session session = conn.createSession(false, QueueSession.AUTO_ACKNOWLEDGE); 
        MessageProducer producer = session.createProducer(destination); 
        File f = new File("photos/" + (String) jComboBoxPhotos.getSelectedItem()); 
        FileInputStream fis = new FileInputStream(f); 
        byte[] data = new byte[(int) f.length()]; 
        fis.read(data); 
        StreamMessage message = session.createStreamMessage(); 
        message.writeString((String) jComboBoxPhotos.getSelectedItem()); 
        message.writeInt(data.length); 
        message.writeBytes(data); 
        producer.send(message); 
       } catch (FileNotFoundException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (JMSException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

       // RQ:si on a pas faitlorsqu'on a crée la session true c-a-d 
       // on a transactionnel(false: n est pas transactionnel) dans 
       // cette il faut faire session.commit(); 
       // session.commit(); 
       // conn.close(); 

      } 
     }); 

    } 

    public void init() { 

     Properties p = new Properties(); 
     p.put(Context.INITIAL_CONTEXT_FACTORY, "orj.jboss.naming.remote.client.InitialContextFactory"); 
     p.put(Context.PROVIDER_URL, "remote://localhost:4447"); 
     p.put(Context.SECURITY_PRINCIPAL, "sid"); 
     p.put(Context.SECURITY_CREDENTIALS, "azerty"); 


     try { 
      Context ctx; 
      ctx = new InitialContext(p); 
      ConnectionFactory factory = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory"); 
      conn = factory.createConnection("sid", "azerty"); 
      destination = (Destination) ctx.lookup("jms/queue/test"); 
      conn.start(); 
     } catch (NamingException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (JMSException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) { 
     new EnvoyeurPhoto(); 
    } 

} 

Hier ist meine Klasse ReceveurJMS:

public class ReceveurJMS extends JFrame { 
    private PanelPhoto jPanelPhoto = new PanelPhoto(); 

    public ReceveurJMS() { 
     this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
     this.setLayout(new BorderLayout()); 
     this.add(jPanelPhoto, BorderLayout.CENTER); 
     this.setBounds(10, 10, 400, 300); 
     this.setVisible(true); 

     Properties p = new Properties(); 
     p.put(Context.INITIAL_CONTEXT_FACTORY, "orj.jboss.naming.remote.client.InitialContextFactory"); 
     // p.put(Context.PROVIDER_URL,"remote://localhost:8080"); 
     p.put(Context.PROVIDER_URL, "remote://localhost:4447"); 
     p.put(Context.SECURITY_PRINCIPAL, "sid"); 
     p.put(Context.SECURITY_CREDENTIALS, "azerty"); 



      try { 
       Context ctx; 
       ctx= new InitialContext(p); 

       ConnectionFactory factory = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory"); 
       Connection conn = factory.createConnection("sid", "azerty"); 
       Destination destination = (Destination) ctx.lookup("jms/queue/test"); 
       Session session = conn.createSession(false, QueueSession.AUTO_ACKNOWLEDGE); 
       MessageConsumer consumer = session.createConsumer(destination); 
       //conn.start(); 
       consumer.setMessageListener(new MessageListener() { 

        @Override 
        public void onMessage(Message message) { 



          try { 
           StreamMessage m = (StreamMessage) message; 
           String nomPhoto = m.readString(); 
           int length = m.readInt(); 
           byte[] data = new byte[length]; 
           m.readBytes(data); 
           ByteArrayInputStream bais = new ByteArrayInputStream(data); 
           BufferedImage bi = ImageIO.read(bais); 
           jPanelPhoto.setBufferedImage(bi); 
           jPanelPhoto.repaint(); 
          } catch (JMSException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } catch (IOException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } 

        } 
       }); 
       conn.start(); 
      } catch (NamingException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (JMSException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

    } 

    public static void main(String[] args) { 
     new ReceveurJMS(); 

    } 
} 
+0

Sie müssen einige jboss client jars zu Ihrem Anwendungspfad hinzufügen. Diese Gläser hängen von Ihrer Version von jboss ab. Siehe die jboss-Dokumentation. –

+0

Ich habe bereits jboss-client.jar – khalid

+0

hinzugefügt, was Sie Version? es mehr ein Glas –

Antwort

0

Ok vielleicht haben Sie einen Fehler in der Konfiguration haben:

p.put(Context.INITIAL_CONTEXT_FACTORY, "orj.jboss.naming.remote.client.InitialContextFactory"); 

Da orj .jboss.naming.remote.client.InitialContextFactory Ich denke, der gute Name ist org .jboss.naming.remote.client.InitialContextFactory

+0

vielen Dank Mr_Thorynque arbeiten hinzuzufügen, es funktioniert. – khalid

+0

so können Sie meine Antwort bestätigen, danke. –

+0

Es tut mir so leid, ich habe deinen Kommentar nicht gesehen. – khalid

Verwandte Themen