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

Jakarta ee 错误:需要在环境或系统属性中指定类名,jakarta-ee,jndi,Jakarta Ee,Jndi,我是开发JavaEE应用程序的新手,对此我很困惑。我已经找到了很多答案,但我无法解决我的问题 这就是错误: javax.naming.NoInitialContextException:需要在环境或系统属性中指定类名,或作为小程序参数,或在应用程序资源文件中指定类名:java.naming.factory.initial 这是我的代码: public class Test { public static void main(String[] args) { List&l

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

这就是错误:

javax.naming.NoInitialContextException:需要在环境或系统属性中指定类名,或作为小程序参数,或在应用程序资源文件中指定类名: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());
    }

log4j:WARN找不到记录器(org.jboss.logging)的appender。
log4j:警告请正确初始化log4j系统。
log4j:请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig 更多信息。
javax.naming.NamingException:未能创建远程连接[根异常为java.lang.IllegalArgumentException:XNIO001001:未找到XNIO提供程序]
位于org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:51)
位于org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:152)
位于javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
位于javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
位于javax.naming.InitialContext.init(InitialContext.java:244)
位于javax.naming.InitialContext。(InitialContext.java:216)
at tn.orange.pfe.test.test.main(test.java:41)
原因:java.lang.IllegalArgumentException:XNIO001001:未找到XNIO提供程序
位于org.xnio.xnio.doGetInstance(xnio.java:226)
位于org.xnio.xnio.getInstance(xnio.java:192)
位于org.jboss.naming.remote.client.EndpointCache.get(EndpointCache.java:47)
位于org.jboss.naming.remote.client.InitialContextFactory.createEndpoint(InitialContextFactory.java:226)
位于org.jboss.naming.remote.client.InitialContextFactory.getOrCreateEndpoint(InitialContextFactory.java:207)
位于org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:170)
位于org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:146)
... 还有5个
java.lang.NullPointerException
位于tn.orange.pfe.test.test.main(test.java:46)
erreurjava.lang.NullPointerException

这是更新后的代码:

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

    }

}
公共类测试{
公共静态void main(字符串[]args){
List auto2=新建ArrayList();
GestionCellRef2GRemote t=null;
Context-Context=null;
//GestionCellRefDualModeReMode p=null;
//Auto_Dualmode autodualmode=新的Auto_Dualmode();
FileInputStream文件=null;
HSSF工作手册类=空;
HSSFSheet feuille=null;
行roww=null;
Properties prop=新属性();
put(Context.INITIAL\u Context\u工厂,“org.jboss.naming.remote.client.InitialContextFactory”);
prop.put(Context.PROVIDER_URL,“http-remoting://localhost:8181");
put(“jboss.naming.client.ejb.context”,true);
put(Context.URL_PKG_前缀,“org.jboss.ejb.client.naming”);
试一试{
试一试{
contxt=新的初始上下文(prop);
}
捕获(NamingE例外)
{e.printStackTrace();}
t=(GestionCellRef2GRemote)contxt.lookup(/GestionCellRef2G!tn.orange.pfe.services.GestionCellRef2GRemote”);
file=newfileinputstream(新文件(“test.xls”);
classeur=新的HSSF工作手册(文件);
feuille=classeur.getSheetAt(0);
int i=1;
while(roww!=null){
roww=feuille.getRow(i);
用于(Auto_2G auto2g:auto2){
auto2g.setBSC_名称(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.setbch(Long.parseLong(roww.getCell(15.getStringCellValue());
//字符串a=(Integer.parseInt(roww.getCell(12.getStringCellValue())*10+roww.getCell(13.getStringCellValue());
//int b=整数.parseInt(a);
//auto2g.setBSIC_dec(b);
//字符串y=(Integer.parseInt(roww.getCell(13.getStringCellValue())*8+roww.getCell(12.getStringCellValue());
//int x=整数。parseInt(y);
//自动2g.setBSIC_oct(x);
auto2g.setNumber_of_GSM_Cell的_2G_Neighbor_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()));
自动2g.立根宽度(65);
auto2g.setNo\u BCCH\u Freq\u list(Float.parseFloat(roww.getCell(16.getStringCellValue());
t、 ajout2G(自动2G);
}
i++;
}
file.close();
}捕获(例外e){
系统输出打印项次(“错误”+e);
e、 printStackTrace();
}
用于(Auto_2G auto2g:auto2){
System.out.println(auto2g.getId());
}
//这是一个很好的例子
//普雷米埃学院
//弗耶河畔的风景区
//迭代器rowIterator=feuille.Iterator();
//插入法
//p.ajoutDm(自动模式);
}
}

这是更新后的代码:

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

    }

}
公共类测试{
公共静态void main(字符串[]args){
List auto2=新建ArrayList();
GestionCellRef2GRemote t=null;
Context-Context=null;
//GestionCellRefDualModeReMode p=null;
//Auto_Dualmode autodualmode=新的Auto_Dualmode();
FileInputStream文件=null;
HSSF工作手册类=空;
HSSFSheet feuille=null;
行roww=null;
Properties prop=新属性();
prop.put(Context.INITIAL\u Context\u工厂),org.jbos
  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);

    }

}