0
votes

I am a new programmer and I want to write java program and use CityGML4j library for it. I saw some example of citygml4j programs but when I run them in netbeans I saw below error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/xml/stream/writers/XMLWriter at org.citygml4j.builder.jaxb.xml.io.writer.JAXBOutputFactory.createCityGMLWriter(Unknown Source) at org.citygml4j.builder.jaxb.xml.io.writer.JAXBOutputFactory.createCityGMLWriter(Unknown Source) at buildingcreator.BuildingCreator.doMain(BuildingCreator.java:113) at buildingcreator.BuildingCreator.main(BuildingCreator.java:46) Caused by: java.lang.ClassNotFoundException: com.sun.xml.stream.writers.XMLWriter at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

Java program:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package buildingcreator;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.citygml4j.CityGMLContext;
import org.citygml4j.builder.CityGMLBuilder;
import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.CityGMLClass;
import org.citygml4j.model.citygml.building.AbstractBoundarySurface;
import org.citygml4j.model.citygml.building.BoundarySurfaceProperty;
import org.citygml4j.model.citygml.building.Building;
import org.citygml4j.model.citygml.building.GroundSurface;
import org.citygml4j.model.citygml.building.RoofSurface;
import org.citygml4j.model.citygml.building.WallSurface;
import org.citygml4j.model.citygml.core.CityModel;
import org.citygml4j.model.citygml.core.CityObjectMember;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.model.gml.geometry.complexes.CompositeSurface;
import org.citygml4j.model.gml.geometry.primitives.Polygon;
import org.citygml4j.model.gml.geometry.primitives.Solid;
import org.citygml4j.model.gml.geometry.primitives.SolidProperty;
import org.citygml4j.model.gml.geometry.primitives.SurfaceProperty;
import org.citygml4j.model.module.citygml.CityGMLVersion;
import org.citygml4j.util.gmlid.DefaultGMLIdManager;
import org.citygml4j.util.gmlid.GMLIdManager;
import org.citygml4j.xml.io.CityGMLOutputFactory;
import org.citygml4j.xml.io.writer.CityGMLWriter;

/**
 *
 * @author Simin
 */
public class BuildingCreator {
    public static void main(String[] args) throws Exception {
        new BuildingCreator().doMain();
    }

    public void doMain() throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

        System.out.println(df.format(new Date()) + "setting up citygml4j context and JAXB builder");
        CityGMLContext ctx = new CityGMLContext();
        CityGMLBuilder builder = ctx.createCityGMLBuilder();

        System.out.println(df.format(new Date()) + "creating LOD2 building as citygml4j in-memory object tree");
        GMLGeometryFactory geom = new GMLGeometryFactory();

        GMLIdManager gmlIdManager = DefaultGMLIdManager.getInstance();

        Building building = new Building();

        Polygon ground = geom.createLinearPolygon(new double[] {0,0,0, 0,12,0, 6,12,0, 6,0,0, 0,0,0}, 3);
        Polygon wall_1 = geom.createLinearPolygon(new double[] {6,0,0, 6,12,0, 6,12,6, 6,0,6, 6,0,0}, 3);
        Polygon wall_2 = geom.createLinearPolygon(new double[] {0,0,0, 0,0,6, 0,12,6, 0,12,0, 0,0,0}, 3);
        Polygon wall_3 = geom.createLinearPolygon(new double[] {0,0,0, 6,0,0, 6,0,6, 3,0,9, 0,0,6, 0,0,0}, 3);
        Polygon wall_4 = geom.createLinearPolygon(new double[] {6,12,0, 0,12,0, 0,12,6, 3,12,9, 6,12,6, 6,12,0}, 3);
        Polygon roof_1 = geom.createLinearPolygon(new double[] {6,0,6, 6,12,6, 3,12,9, 3,0,9, 6,0,6}, 3);
        Polygon roof_2 = geom.createLinearPolygon(new double[] {0,0,6, 3,0,9, 3,12,9, 0,12,6, 0,0,6}, 3);

        ground.setId(gmlIdManager.generateUUID());
        wall_1.setId(gmlIdManager.generateUUID());
        wall_2.setId(gmlIdManager.generateUUID());
        wall_3.setId(gmlIdManager.generateUUID());
        wall_4.setId(gmlIdManager.generateUUID());
        roof_1.setId(gmlIdManager.generateUUID());
        roof_2.setId(gmlIdManager.generateUUID());

        // lod2 solid
        List<SurfaceProperty> surfaceMember = new ArrayList<SurfaceProperty>();
        surfaceMember.add(new SurfaceProperty('#' + ground.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_1.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_2.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_3.getId()));
        surfaceMember.add(new SurfaceProperty('#' + wall_4.getId()));
        surfaceMember.add(new SurfaceProperty('#' + roof_1.getId()));
        surfaceMember.add(new SurfaceProperty('#' + roof_2.getId()));

        CompositeSurface compositeSurface = new CompositeSurface();
        compositeSurface.setSurfaceMember(surfaceMember);       
        Solid solid = new Solid();
        solid.setExterior(new SurfaceProperty(compositeSurface));

        building.setLod2Solid(new SolidProperty(solid));

        // thematic boundary surfaces
        List<BoundarySurfaceProperty> boundedBy = new ArrayList<BoundarySurfaceProperty>();
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_GROUND_SURFACE, ground));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_1));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_2));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_3));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_WALL_SURFACE, wall_4));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_ROOF_SURFACE, roof_1));
        boundedBy.add(createBoundarySurface(CityGMLClass.BUILDING_ROOF_SURFACE, roof_2));       
        building.setBoundedBySurface(boundedBy);

        CityModel cityModel = new CityModel();
        cityModel.setBoundedBy(building.calcBoundedBy(false));
        cityModel.addCityObjectMember(new CityObjectMember(building));

        System.out.println(df.format(new Date()) + "writing citygml4j object tree");
        CityGMLOutputFactory out = builder.createCityGMLOutputFactory(CityGMLVersion.DEFAULT);
            CityGMLWriter writer = out.createCityGMLWriter(new File("LOD2_Building_v200.gml"));
        writer.setPrefixes(CityGMLVersion.DEFAULT);
        writer.setSchemaLocations(CityGMLVersion.DEFAULT);
        writer.setIndentString("  ");
        writer.write(cityModel);    
                writer.close(); 

        System.out.println(df.format(new Date()) + "CityGML file LOD2_Building_v200.gml written");
        System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
    }

    private BoundarySurfaceProperty createBoundarySurface(CityGMLClass type, Polygon geometry) {
        AbstractBoundarySurface boundarySurface = null;

        switch (type) {
        case BUILDING_WALL_SURFACE:
            boundarySurface = new WallSurface();
            break;
        case BUILDING_ROOF_SURFACE:
            boundarySurface = new RoofSurface();
            break;
        case BUILDING_GROUND_SURFACE:
            boundarySurface = new GroundSurface();
            break;
        default:
            break;
        }

        if (boundarySurface != null) {
            boundarySurface.setLod2MultiSurface(new MultiSurfaceProperty(new MultiSurface(geometry)));
            return new BoundarySurfaceProperty(boundarySurface);
        }

        return null;

        }
}
1
Do you have the JAR installed correctly?AvetisG
I linked jar file to project at project propertiesuser2169474

1 Answers

0
votes

Also put all dependent JARs on your classpath. You will find these JARs in the lib subfolder of the citygml4j distribution package. Which version of citygml4j are you using? It seems you are lacking sjsxp.jar on your classpath. However, sjsxp.jar was replaced in the latest version 2.2 of citygml4j.

citygml4j is also available as Maven artifact. This makes dependency management much more simple.

<dependency>
  <groupId>org.citygml4j</groupId>
  <artifactId>citygml4j</artifactId>
  <version>2.2</version>
</dependency>