错误:需要在环境或系统属性中指定类名

时间:2016-03-21 09:23:52

标签: java-ee jndi

我是Java EE应用程序开发的新手,我对此非常困惑。我找到了很多答案,但我无法解决我的问题。

这是错误:

  

javax.naming.NoInitialContextException:需要在环境或系统属性中指定类名,或在applet参数中或在应用程序资源文件中指定类名:java.naming.factory.initial

这是我的代码:

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());
    }

这是我的 JNDI.properties 文件:

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

1 个答案:

答案 0 :(得分: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>
相关问题