添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I use the citygml4j-2.6.0.jar in a java project to read a gml file,it runs very well.
But,when use it in a java web project,exception as follows:
org.citygml4j.builder.CityGMLBuilderException: Failed to build JAXB context.
at org.citygml4j.builder.jaxb.JAXBBuilderFactory.build(JAXBBuilderFactory.java:72)
at org.citygml4j.CityGMLContext.createJAXBBuilder(CityGMLContext.java:130)
at org.citygml4j.CityGMLContext.createCityGMLBuilder(CityGMLContext.java:122)
at com.smartearth.lod4citygml.service.SimpleReadRoomInfo.readBuilding(SimpleReadRoomInfo.java:67)
at com.smartearth.lod4citygml.service.SimpleReadRoomInfo.getRoomInfoList(SimpleReadRoomInfo.java:110)
at com.smartearth.lod4citygml.controller.RoomListController.doPost(RoomListController.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1368)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "net.opengis.citygml._2" 不包含 ObjectFactory.class 或 jaxb.index

  • with linked exception:
    [javax.xml.bind.JAXBException: "net.opengis.citygml._2" 不包含 ObjectFactory.class 或 jaxb.index]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:146)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:356)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:431)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:394)
    at org.citygml4j.builder.jaxb.JAXBBuilderFactory.build(JAXBBuilderFactory.java:70)
    ... 29 more
    Caused by: javax.xml.bind.JAXBException: "net.opengis.citygml._2" 不包含 ObjectFactory.class 或 jaxb.index
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:266)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:171)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:131)
    ... 33 more
    is there any suggestion for me?
  • Are you sure that you are using version 2.6.0? Your stack trace contains classes like org.citygml4j.builder.jaxb.JAXBBuilderFactory which however have been removed in 2.6.0.

    Or maybe you have both version 2.6.0 and an older version on your classpath at the same time? This might explain the errors.

    sorry,I made a mistake ,but when i create a new java web project,it still exist the similar exceptions:
    org.citygml4j.builder.jaxb.CityGMLBuilderException: Failed to build JAXB context.
    at org.citygml4j.builder.jaxb.CityGMLBuilderFactory.build(CityGMLBuilderFactory.java:70)
    at org.citygml4j.CityGMLContext.createCityGMLBuilder(CityGMLContext.java:122)
    at com.smartearth.readcitygml.controller.ReadCityGmlController.init(ReadCityGmlController.java:43)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4920)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1439)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:953)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1439)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:953)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:656)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
    Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "net.opengis.citygml._2" 不包含 ObjectFactory.class 或 jaxb.index

  • with linked exception:
    [javax.xml.bind.JAXBException: "net.opengis.citygml._2" 不包含 ObjectFactory.class 或 jaxb.index]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:146)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:356)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:431)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:394)
    at org.citygml4j.builder.jaxb.CityGMLBuilderFactory.build(CityGMLBuilderFactory.java:68)
    ... 35 more
    Caused by: javax.xml.bind.JAXBException: "net.opengis.citygml._2" 不包含 ObjectFactory.class 或 jaxb.index
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:266)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:171)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:131)
    ... 39 more
  • No,Java 8,when i use the citygml4j-2.6.0.jar in java project,it works well,no exceptions,the exception exists in java web project,and i depoly the web project in a tomcat 9.The web project is very simple project,i write some codes in a servlet,the codes in servlet as follows:

    public void init(ServletConfig config) throws ServletException {

    	String path = config.getServletContext().getRealPath("/") + "\\WEB-INF\\classes\\city.gml";
    	CityGMLContext ctx = CityGMLContext.getInstance();
    	try {
    		CityGMLBuilder builder = ctx.createCityGMLBuilder();
    		CityGMLInputFactory in = builder.createCityGMLInputFactory();
    		in.setProperty(CityGMLInputFactory.SUPPORT_CITYGML_VERSION_0_4_0, true);
    		CityGMLReader reader = in.createCityGMLReader(new File(path));
    		CityModel cityModel = (CityModel)reader.nextFeature();
    		reader.close();
    		System.out.println(cityModel);
    	} catch (CityGMLBuilderException | CityGMLReadException e) {
    		e.printStackTrace();
              

    I'm also using citygml4j in several servlets without facing the above issue (based on Tomcat 8.5 though).

    Maybe it's a class loader problem. Per default, the CityGMLBuilder instance is created using the system class loader. In your scenario, the system class loader might not be appropriate to find and load the JAXB classes in the package "net.opengis.citygml._2" (see your stack trace).

    In your code, please try and use the createCityGMLBuilder(ClassLoader classLoader) method of CityGMLContext instead to create the CityGMLBuilder. This method accepts a class loader which is then used to load the JAXB classes. Maybe passing getClass().getClassLoader() to this method already solves your issue.

    Good to hear that it works now. Well, maybe the system class loader should not be used by citygml4j per default to avoid this issue in the first place. I will take a look at this. If you want play around with the sources yourself, then check line 32 in the CityGMLBuilderFactory.java class.

    Another important hint: Creating an instance of CityGMLBuilder takes time due to the JAXB classes being loaded in the background. So make sure to only create CityGMLBuilder once and to reuse this instance throughout your (web) application.