2016-03-21 12 views
0

Java EE uygulamalarının geliştirilmesinde yeniyim ve bu konuda gerçekten kafam karıştı. Çok fazla cevap buldum ama sorunumu çözemiyorum. Hata: Ortam veya sistem özelliğinde sınıf adı belirtmeniz gerekiyor

Bu

hatadır:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

Ve bu benim kodudur:

public class Test { 

    public static void main(String[] args) { 
     List<Auto_2G> auto2 = new ArrayList<Auto_2G>(); 
     GestionCellRef2GRemote t = null; 
     Context contxt=null ; 
     //GestionCellRefDualmodeRemote p = null; 
     //Auto_Dualmode autodualmode = new Auto_Dualmode(); 
     FileInputStream file=null; 
     HSSFWorkbook classeur=null ; 
     HSSFSheet feuille=null; 
     Row roww=null; 

     try { 
      try { 
       contxt = new InitialContext(); 
      } catch(NamingException e) { 

      } 
      t = (GestionCellRef2GRemote) contxt.lookup("/webpfe/GestionCellRef2G!tn.orange.pfe.services.GestionCellRef2GR emote"); 
      file= new FileInputStream(new File("test.xls")); 
      classeur = new HSSFWorkbook(file); 
      feuille = classeur.getSheetAt(0); 
      int i=1; 

      while(roww!=null) { 
       roww=feuille.getRow(i); 

       for (Auto_2G auto2g:auto2) { 
        auto2g.setBSC_Name(roww.getCell(0).getStringCellValue()); 
        auto2g.setBTS_NAME(roww.getCell(2).getStringCellValue()); 
        auto2g.setCELL_NAME(roww.getCell(4).getStringCellValue()); 

        t.ajout2G(auto2g); 
       } 
       i++; 
      } 
      file.close(); 
     } catch (Exception e) { 
      System.out.println("erreur"+e); 
     } 

     for(Auto_2G auto2g:auto2){ 
     System.out.println(auto2g.getId()); 
    } 

Ve bu dosya benim JNDI.properties geçerli:

java.naming.factory.url.pkgs=org.jboss.ejb.client.naming 
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory 
java.naming.provider.url=http-remoting://localhost:8181 
jboss.naming.client.ejb.context=true 
jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false 

log4j:WARN No appenders could be found for logger (org.jboss.logging). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 
javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.IllegalArgumentException: XNIO001001: No XNIO provider found] 
    at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:51) 
    at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:152) 
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) 
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313) 
    at javax.naming.InitialContext.init(InitialContext.java:244) 
    at javax.naming.InitialContext.<init>(InitialContext.java:216) 
    at tn.orange.pfe.test.Test.main(Test.java:41) 
Caused by: java.lang.IllegalArgumentException: XNIO001001: No XNIO provider found 
    at org.xnio.Xnio.doGetInstance(Xnio.java:226) 
    at org.xnio.Xnio.getInstance(Xnio.java:192) 
    at org.jboss.naming.remote.client.EndpointCache.get(EndpointCache.java:47) 
    at org.jboss.naming.remote.client.InitialContextFactory.createEndpoint(InitialContextFactory.java:226) 
    at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateEndpoint(InitialContextFactory.java:207) 
    at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:170) 
    at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:146) 
    ... 5 more 
java.lang.NullPointerException 
    at tn.orange.pfe.test.Test.main(Test.java:46) 
erreurjava.lang.NullPointerException 
+0

* jndi.properties * 'i yüklemeniz ve 'InitialContext''e aktarmanız gerekmektedir. Bir JNDI Bağlamı Oluşturma * ve * JNDI Ortamı * burada belirtilen [https://docs.oracle.com/cd/B14099_19/web.1012/b14012/jndi.htm]. – aribeiro

+0

Teşekkürler, göreceğim ^^ – MOhamed

+0

@MOhamed JNDI.properties sınıf yolunda değil veya jndi.properties (küçük harf) olarak yeniden adlandırılmalıdır iki nedeni düşünebilirsiniz. Ancak, bu özellik dosyasında bir sorun olup olmadığını görmek için hızlı bir kontrol olarak, bu özellikleri bir 'Properties 'nesnesinde' Properties prop = new Properties(); prop.put (Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); prop.put (Context.PROVIDER_URL, "http-remoting: // localhost: 8181"); vb. ve InitialContext'e 'Context context = new InitialContext (prop)' olarak aktarın; –

cevap

0
This is the code after the update : 


    <pre> 
    public class Test { 

    public static void main(String[] args) { 
     List<Auto_2G> auto2 = new ArrayList<Auto_2G>(); 
     GestionCellRef2GRemote t = null; 
     Context contxt=null ; 
     //GestionCellRefDualmodeRemote p = null; 
     //Auto_Dualmode autodualmode = new Auto_Dualmode(); 
     FileInputStream file=null; 
     HSSFWorkbook classeur=null ; 
     HSSFSheet feuille=null; 
     Row roww=null; 
     Properties prop = new Properties(); 
     prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
     prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8181"); 
     prop.put("jboss.naming.client.ejb.context", true); 
     prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
try { 

    try{ 
     contxt = new InitialContext(prop); 
    } 
    catch (NamingException e) 
    {e.printStackTrace();}  

    t = (GestionCellRef2GRemote) contxt.lookup("/GestionCellRef2G!tn.orange.pfe.services.GestionCellRef2GRemote"); 
    file= new FileInputStream(new File("test.xls")); 
    classeur = new HSSFWorkbook(file); 
feuille = classeur.getSheetAt(0); 
int i=1; 

while(roww!=null){ 
     roww=feuille.getRow(i); 
     for(Auto_2G auto2g:auto2){ 
    auto2g.setBSC_Name(roww.getCell(0).getStringCellValue()); 
    auto2g.setBTS_NAME(roww.getCell(2).getStringCellValue()); 
    auto2g.setCELL_NAME(roww.getCell(4).getStringCellValue()); 
    auto2g.setLAC(Long.parseLong(roww.getCell(10).getStringCellValue())); 
    auto2g.setCell_CI(Long.parseLong(roww.getCell(11).getStringCellValue())); 
    auto2g.setBCC(Integer.parseInt(roww.getCell(12).getStringCellValue())); 
    auto2g.setNCC(Integer.parseInt(roww.getCell(13).getStringCellValue())); 
    auto2g.setBand(roww.getCell(14).getStringCellValue()); 
    auto2g.setBCCH(Long.parseLong(roww.getCell(15).getStringCellValue())); 
    //String a =(Integer.parseInt(roww.getCell(12).getStringCellValue()))*10+roww.getCell(13).getStringCellValue(); 
    //int b = Integer.parseInt(a); 
    //auto2g.setBSIC_dec(b); 
    //String y=(Integer.parseInt(roww.getCell(13).getStringCellValue()))*8+roww.getCell(12).getStringCellValue(); 
// int x= Integer.parseInt(y); 
    //auto2g.setBSIC_oct(x); 
    auto2g.setNumber_of_2G_Neighbor_Cell_for_GSM_Cell(Integer.parseInt(roww.getCell(28).getStringCellValue())); 
    auto2g.setNumber_of_3G_Neighbor_Cell_for_GSM_Cell(Integer.parseInt(roww.getCell(29).getStringCellValue())); 
    auto2g.setNumber_of_GSM_TRX(Integer.parseInt(roww.getCell(17).getStringCellValue())); 
    auto2g.setBramwidth(65); 
    auto2g.setNo_BCCH_Freq_list(Float.parseFloat(roww.getCell(16).getStringCellValue())); 
    t.ajout2G(auto2g); 
     } 

    i++; 

    } 


    file.close(); 

} catch (Exception e) { 
System.out.println("erreur"+e); 
e.printStackTrace(); 
} 


for(Auto_2G auto2g:auto2){ 
    System.out.println(auto2g.getId()); 
} 

      // Créer un objet classuer 



      // Lire la première feuille de ce classuer 


      // Créer un Itérateur sur la feuille 
      //Iterator<Row> rowIterator = feuille.iterator(); 



     // insertion en BD 

     // p.ajoutDm(autodualmode); 

    } 

} 
    </pre> 
+0

Güncellenen kodunuz hala okuyor "contxt = yeni InitialContext(); '. 'Contxt = yeni InitialContext (prop) olmalı '' –

+0

hayır bir yazım hatası özür dilerim şimdi ^^ – MOhamed

+0

@MadhusudanaReddySunnapu çözerim ve eğer sorun ne olduğunu bilseydim beni öldürür: p – MOhamed

İlgili konular