How to run OpenLayers using localhost?

I already installed Apache Tomcat and GeoServer war.

In what folder should I place all the OpenLayers file?

  • Please edit your question to include details of what you've attempted and what happens when you try it
    – Midavalo
    Feb 25, 2019 at 4:23

2 Answers 2


Openlayers is Javascript library which runs within html page. If it is plain html page than you can run it from wherever you want. If you run OpenLayers within web app (written in PHP, Python or similar) than you might need a web server. Here is basic setup instructions for OpenLayers: https://openlayers.org/en/latest/doc/quickstart.html

If you have enough skills you can build OpenLayers app: https://openlayers.org/en/latest/doc/tutorials/bundle.html

Tomcat runs geoserver and geoserver serves spatial data through OGC services such as WMS, WFS which can Openlayers then serve and show within HTML page. Example of displaying WMS layer: https://openlayers.org/en/latest/examples/wms-tiled.html

Example of displaying WFS layer: https://openlayers.org/en/latest/examples/vector-wfs.html

Example of displaying GeoJSON file: https://openlayers.org/en/latest/examples/geojson.html


You can put your HTML and JavaScript pages in the www directory of your GeoServer data directory. GeoServer will then serve it at http://localhost:8080/geoserver/mypage.html (or whatever you call your page). This will avoid any cross-origin request issues and avoids the need for another server.

Not the answer you're looking for? Browse other questions tagged or ask your own question.