我的ant构建突然开始给出javax.naming.NoInitialContextException:需要在环境或系统



我有一个build.xml文件,直到昨天才完全工作,今天它突然开始给出下面的异常…我没有在应用程序中做任何修改,它之前成功地识别了JNDI名称,我不明白是什么导致它现在失败了。

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 

建立日志如下。

schemaexport:
[hibernatetool] Executing Hibernate Tool with a JPA Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.jboss.logging).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[hibernatetool] SLF4J: Class path contains multiple SLF4J bindings.
[hibernatetool] SLF4J: Found binding in [jar:file:/C:/vseelsh_workspace/vseelsh_perforce_ws/pem_rd/NBDX/nbdx/lib/gwt/gwt-2.3.0/gwt-2.3.0/samples/DynaTableRf/war/WEB-INF/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
[hibernatetool] SLF4J: Found binding in [jar:file:/C:/Jboss/jboss-as-7.1.1.Final/modules/org/slf4j/impl/main/slf4j-jboss-logmanager-1.0.0.GA.jar!/org/slf4j/impl/StaticLoggerBinder.class]
[hibernatetool] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.service.jndi.JndiException: Error parsing JNDI name [java:/nbdxDS]
[hibernatetool] 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
BUILD FAILED
C:vseelsh_workspacevseelsh_perforce_wspem_rdNBDXnbdxbuild.xml:189: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [java:/nbdxDS]
    at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:226)
    at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:189)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [java:/nbdxDS]
    at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:63)
    at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:111)
    at org.hibernate.tool.hbm2x.Hbm2DDLExporter.doStart(Hbm2DDLExporter.java:165)
    at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)
    at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
    at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
    ... 15 more
Caused by: 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
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
    at javax.naming.InitialContext.getNameParser(InitialContext.java:499)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86)
    ... 25 more
Total time: 13 seconds

似乎您的hibernate版本已升级,因此可能出现"解析JNDI名称错误"。

如果hibernate-cfg.xml文件是自动生成的,那么您应该删除会话工厂中的name属性,以避免JNDI解析问题。

 <session-factory>
不是

 <session-factory name="">

相关内容

  • 没有找到相关文章

最新更新