index.rst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. .. _eclipse_guide:
  2. Eclipse Guide
  3. =============
  4. A reference for developing GeoServer with Eclipse.
  5. .. contents:: :local:
  6. Setting up Eclipse
  7. ------------------
  8. Use of Maven M2 Plugin
  9. ^^^^^^^^^^^^^^^^^^^^^^
  10. The Eclipse built-in support for maven can be used to build and run GeoServer, see :ref:`quickstart_eclipse_m2` for details.
  11. Use of maven eclipse plugin
  12. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13. The maven eclipse plugin is used to generate eclipse projects for a set of
  14. modules::
  15. mvn eclipse:eclipse
  16. After which the modules can be imported into an eclipse workspace, see :ref:`quickstart_eclipse` for details.
  17. A useful feature of the plugin is the ability to download associated source code
  18. for third party dependencies. This is done with the ``downloadSources`` flag::
  19. mvn -DdownloadSources eclipse:eclipse
  20. .. warning::
  21. The first time you enable the ``downloadSources`` flag the build will take a long time as it will attempt to download the sources for every single library GeoServer depends on.
  22. Running and debugging
  23. ---------------------
  24. Run or debug the class ``org.geoserver.web.Start`` in the ``web-app``
  25. module. The steps to do so are detailed in the :ref:`quickstart_eclipse` or :ref:`quickstart_eclipse_m2`.
  26. Running GeoServer with Extensions
  27. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  28. By default, GeoServer will run without any extensions enabled. In order to run GeoServer with extensions, the ``web-app`` module declares a number of profiles used to enable specific extensions when running ``Start``. To enable an extension, re-generate the root eclipse profile with the appropriate maven profile(s) enabled::
  29. % mvn eclipse:eclipse -P wps
  30. The full list of supported profiles can be found in ``src/web/app/pom.xml``.
  31. Setting the data directory
  32. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  33. If unset, GeoServer will default to the ``minimal`` directory inside of the
  34. ``web-app`` module for its data directory. To change this:
  35. #. Open ``Debug Configurations...`` from the Eclipse menu
  36. .. image:: dd1.jpg
  37. #. Select the ``Start`` configuration, select the ``Arguments`` panel and
  38. specify the ``-DGEOSERVER_DATA_DIR`` parameter, setting it to the absolute
  39. path of the data directory
  40. .. image:: dd2.jpg
  41. Changing the default port for Jetty
  42. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  43. If unset, Jetty will default to port ``8080``. To change this:
  44. #. Open the ``Arguments`` panel of the ``Start`` configuration as described
  45. in the above section
  46. #. Specify the ``-Djetty.port`` parameter, setting it to the desired port
  47. .. image:: port.jpg
  48. Configuring JNDI resources in Jetty
  49. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  50. JNDI resources such as data sources can be configured by supplying a Jetty
  51. server configuration file named in the system property ``jetty.config.file``,
  52. specified as a line in ``VM arguments`` in the ``Arguments`` panel of the launch
  53. configuration for ``Start`` (separate lines are joined when the JVM is launched).
  54. The path to the configuration file is relative to the root of the ``web-app`` module,
  55. in which the launch configuration runs. Naming factory system properties must also be
  56. configured for Jetty. For example, ``VM arguments`` could include::
  57. -Djetty.config.file=../../../../../settings/jetty.xml
  58. -Djava.naming.factory.url.pkgs=org.eclipse.jetty.jndi
  59. -Djava.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
  60. The following Jetty server configuration file
  61. configures a JNDI data source ``java:comp/env/jdbc/demo`` that is a
  62. connection pool for an Oracle database::
  63. <?xml version="1.0"?>
  64. <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
  65. <Configure class="org.eclipse.jetty.server.Server">
  66. <New class="org.eclipse.jetty.plus.jndi.Resource">
  67. <Arg>java:comp/env/jdbc/demo</Arg>
  68. <Arg>
  69. <New class="org.apache.commons.dbcp.BasicDataSource">
  70. <Set name="driverClassName">oracle.jdbc.OracleDriver</Set>
  71. <Set name="url">jdbc:oracle:thin:@oracle.example.com:1521:demodb</Set>
  72. <Set name="username">claudius</Set>
  73. <Set name="password">s3cr3t</Set>
  74. <Set name="maxActive">20</Set>
  75. <Set name="maxIdle">10</Set>
  76. <Set name="minIdle">0</Set>
  77. <Set name="maxWait">10000</Set>
  78. <Set name="minEvictableIdleTimeMillis">300000</Set>
  79. <Set name="timeBetweenEvictionRunsMillis">300000</Set>
  80. <Set name="numTestsPerEvictionRun">20</Set>
  81. <Set name="poolPreparedStatements">true</Set>
  82. <Set name="maxOpenPreparedStatements">100</Set>
  83. <Set name="testOnBorrow">true</Set>
  84. <Set name="validationQuery">SELECT SYSDATE FROM DUAL</Set>
  85. <Set name="accessToUnderlyingConnectionAllowed">true</Set>
  86. </New>
  87. </Arg>
  88. </New>
  89. </Configure>
  90. Jetty does not mandate a ``reference-ref`` in GeoServer ``WEB-INF/web.xml``,
  91. so there is no need to modify that file. No Jetty-specific information is
  92. required inside the GeoServer ``web-app`` module or data directory, so JNDI
  93. resources can be tested under Jetty for later deployment under Tomcat.
  94. See also the tutorial `Setting up a JNDI connection pool with Tomcat
  95. <http://docs.geoserver.org/stable/en/user/tutorials/tomcat-jndi/tomcat-jndi.html>`_
  96. in the GeoServer User Manual.
  97. Starting Jetty with an open SSL port
  98. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  99. The SSL port used ``8443``.
  100. #. Open the ``Arguments`` panel of the ``Start`` configuration.
  101. #. Specify the ``-Dssl.hostname`` parameter, setting it to the full qualified host name of the box
  102. running Jetty.
  103. .. image:: ssl.jpeg
  104. On first time startup, a key store is created in ``<home directory>/.geoserver/keystore.jks``.
  105. The password is **changeit** and the key store contains a self-signed certificate for the host name
  106. passed in the ``ssl.hostname`` parameter.
  107. Test the SSL connection by opening a browser and entering
  108. **https://ux-desktop03.mc-home.local:8443/geoserver**. The browser should complain about the self-signed certificate which does not hurt for test and development setups.
  109. Eclipse preferences
  110. -------------------
  111. Code formatting
  112. ^^^^^^^^^^^^^^^
  113. The Google formatter plugin is embedded in the build and will reformat the code at each build, matching the coding conventions. Please always build before committing!
  114. The `google-java-format <https://github.com/google/google-java-format>`__ project offers a plugin for Eclipse, but we are waiting an support for ASOP variant. While we wait for this fix build once on the command line, to format the any code changes before committing.
  115. As workaround you could use a `modified version <https://github.com/fernandor777/google-java-format/releases/download/1.7-gsgt/google-java-format-eclipse-plugin-1.6.0.jar>`__ with 4 spaces indent by default, putting the jar file on Eclipse dropins folder.
  116. You may also:
  117. #. Download https://github.com/geotools/geotools/blob/main/build/eclipse/eclipse-java-google-style.xml
  118. #. Navigate to ``Java``, ``Code Style``, ``Formatter`` and click ``Import...``
  119. #. Select the ``eclipse-java-google-style.xml`` file downloaded in step 1
  120. #. Click ``Apply``
  121. .. image:: code_formatting2.png
  122. #. We follow `Google Code Formatting <https://google.github.io/styleguide/javaguide.html>`__ with the AOSP variant (4 spaces indent instead of 2).
  123. For more information see GeoTools `Coding Style <http://docs.geotools.org/latest/developer/conventions/code/style.html>`__ page.
  124. Code templates
  125. ^^^^^^^^^^^^^^
  126. #. Download :download:`codetemplates.xml </../../../../build/codetemplates.xml>`.
  127. #. Navigate to ``Java``, ``Code Style``, ``Code Templates`` and click ``Import...``
  128. #. Select the ``codetemplates.xml`` file downloaded in step 1
  129. #. Click ``Apply``
  130. .. image:: code-template.png
  131. Text editors
  132. ^^^^^^^^^^^^
  133. #. Navigate to ``General``, ``Editors``, ``Text Editors``
  134. #. Check ``Insert spaces for tabs``
  135. #. Check ``Show print margin`` and set ``Print margin column`` to "100"
  136. #. Check ``Show line numbers``
  137. #. Check ``Show whitespace characters`` (optional)
  138. .. note::
  139. Showing whitespace characters can help ensure that unnecessary whitespace
  140. is not unintentionally committed.
  141. .. image:: text_editors.png
  142. #. Click ``Apply``