diff --git a/elda-assets/src/main/webapp/WEB-INF/lib/urlrewrite-3.2.0.jar b/elda-assets/src/main/webapp/WEB-INF/lib/urlrewrite-3.2.0.jar deleted file mode 100644 index 214518b36..000000000 Binary files a/elda-assets/src/main/webapp/WEB-INF/lib/urlrewrite-3.2.0.jar and /dev/null differ diff --git a/elda-assets/src/main/webapp/WEB-INF/urlrewrite.xml b/elda-assets/src/main/webapp/WEB-INF/urlrewrite.xml deleted file mode 100644 index 81e8bbd35..000000000 --- a/elda-assets/src/main/webapp/WEB-INF/urlrewrite.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - ^/(lda-assets|specs|API)/(.*)$ - /$1/$2 - - - - ^/$ - index.html - - - - ^/(.*)$ - /API/$1 - - - diff --git a/elda-assets/src/main/webapp/WEB-INF/web.xml b/elda-assets/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index e45005658..000000000 --- a/elda-assets/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - default - / - - - - index.html - - diff --git a/elda-assets/src/main/webapp/logback.xml b/elda-assets/src/main/webapp/logback.xml deleted file mode 100644 index 32cc47ee2..000000000 --- a/elda-assets/src/main/webapp/logback.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - %d{STRICT, UTC} %-5level [%t] (%logger{36}) - %msg%n - - - - - - - - diff --git a/elda-standalone/Dockerfile b/elda-standalone/Dockerfile new file mode 100644 index 000000000..e1303c2c7 --- /dev/null +++ b/elda-standalone/Dockerfile @@ -0,0 +1,10 @@ +FROM amazoncorretto:21-alpine3.20 + +ENV ELDA_PORT=8080 +EXPOSE 8080 + +ENV ELDA_WEBAPP_PATH=/etc/elda + +COPY target/elda-standalone-jar-with-dependencies.jar app.jar + +CMD java -jar /app.jar diff --git a/elda-standalone/pom.xml b/elda-standalone/pom.xml index 7373edfea..5fa32f001 100644 --- a/elda-standalone/pom.xml +++ b/elda-standalone/pom.xml @@ -8,7 +8,7 @@ 3.0.1-SNAPSHOT elda-standalone - war + jar elda-standalone instant Elda webapp @@ -18,21 +18,12 @@ org.apache.tomcat.embed tomcat-embed-core ${tomcat.version} - provided org.apache.tomcat.embed tomcat-embed-jasper ${tomcat.version} - provided - - - - com.epimorphics.lda - elda-assets - ${project.version} - war @@ -57,6 +48,30 @@ elda-standalone + + org.apache.maven.plugins + maven-assembly-plugin + 3.8.0 + + + + run.standalone + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + org.apache.maven.plugins maven-war-plugin diff --git a/elda-standalone/readme.md b/elda-standalone/readme.md new file mode 100644 index 000000000..9a8ca23f1 --- /dev/null +++ b/elda-standalone/readme.md @@ -0,0 +1,54 @@ +# ELDA Standalone Application + +This module contains a standalone ELDA application which runs an embedded Tomcat server. + +To build: +* `mvn clean package` + +To run: +* `java -jar target/elda-standalone-jar-with-dependencies.jar` + +### Sample Web Server + +By default, the application loads a web server configuration, including ELDA API specs, +from the `src/main/webapp` directory, which contains a small sample API. +When running with the sample API, check http://localhost:8080/standalone/again/games.ttl to confirm that the +server is running correctly. + +Note that the sample API does not support HTML rendering. + +### Configuring the Web Server + +To run the application with your own web server configuration, +set the `ELDA_WEBAPP_PATH` environment variable to the path to your web app directory. +This directory **must contain** a `web.xml` file which configures the web server. + +It must also contain the ELDA API specs and static resources (velocity templates, scripts, stylesheets etc.) +you want to serve. + +To run the web server with a context path, set the `ELDA_CONTEXT_PATH` environment variable to the context path. +The default context path is `/standalone`. +To run without a context path set the environment variable to `/`. + +To run the web server with an alternate port (the default is 8080), set the `ELDA_PORT` environment variable to the port number. + +| Env Var | Description | Default | +|---------|-------------|---------| +| `ELDA_WEBAPP_PATH` | The location of the web app directory. | src/main/webapp | +| `ELDA_CONTEXT_PATH` | The context path to the ELDA API. | /standalone | +| `ELDA_PORT` | The port on which the web server answers requests. | 8080 | + +### Docker Image + +To build the standalone application as a Docker image, run: +* `docker build -t elda/standalone:test .` + +The image does not contain any web server configuration or ELDA API specs, +hence these must be mounted to a running container as a volume. +The default web app directory is `/etc/elda`. + +To run the image in a Docker container, run: +* `docker run -p 8080:8080 -v {host webapp dir}:{container webapp dir} -e ELDA_WEBAPP_PATH={container webapp dir} elda/standalone:test` + +For example, to run with the sample web server: +* `docker run -p 8080:8080 -v ./src/main/webapp:/etc/elda -e ELDA_WEBAPP_PATH=/etc/elda elda/standalone:test` diff --git a/elda-standalone/src/main/java/run/standalone.java b/elda-standalone/src/main/java/run/standalone.java index bf051fbc0..52b012dd5 100644 --- a/elda-standalone/src/main/java/run/standalone.java +++ b/elda-standalone/src/main/java/run/standalone.java @@ -12,31 +12,31 @@ import org.apache.catalina.connector.Connector; import org.apache.catalina.startup.Tomcat; +import org.apache.jena.riot.RIOT; -public class standalone { - - static final String standalone = "/standalone"; - static final String ROOT = "/"; +public class standalone { - public static void main( String [] args ) throws Exception { - Tomcat server = new Tomcat(); - int port = 8080; - String portString = System.getProperty("elda.port"); - if (portString != null) port = Integer.parseInt(portString); + public static void main( String [] args ) throws Exception { + RIOT.init(); + Tomcat server = new Tomcat(); + String portString = System.getProperty ("ELDA_PORT"); + int port = portString != null ? Integer.parseInt(portString) : 8080; + + String ctxPath = System.getenv("ELDA_CONTEXT_PATH"); + ctxPath = ctxPath != null ? ctxPath : "/standalone"; + + String basePath = System.getenv("ELDA_WEBAPP_PATH"); + basePath = basePath != null ? basePath : "src/main/webapp"; Connector connector = new Connector(); connector.setPort(port); server.getService().addConnector(connector); - server.setBaseDir("."); - -// System.err.println(">> " + new File(".").getAbsolutePath()); -// String absolutePath = new File("target/elda-standalone").getAbsolutePath(); - String absolutePath = new File("src/main/webapp").getAbsolutePath(); - // System.err.println(">> " + absolutePath); - server.addWebapp(standalone, absolutePath); - server.addWebapp(ROOT, absolutePath); - // + + String absolutePath = new File(basePath).getAbsolutePath(); + server.addWebapp(ctxPath, absolutePath); + + server.getConnector(); server.start(); server.getServer().await(); } diff --git a/elda-standalone/src/main/webapp/WEB-INF/web.xml b/elda-standalone/src/main/webapp/WEB-INF/web.xml index b333abe28..889194103 100644 --- a/elda-standalone/src/main/webapp/WEB-INF/web.xml +++ b/elda-standalone/src/main/webapp/WEB-INF/web.xml @@ -40,7 +40,7 @@ org.glassfish.jersey.servlet.ServletContainer - jersey.config.property.packages + jersey.config.server.provider.packages com.epimorphics.lda.restlets @@ -53,25 +53,18 @@ jersey.spi.container.ContainerRequestFilters org.glassfish.jersey.api.container.filter.PostReplaceFilter + + + jersey.config.servlet.filter.staticContentRegex + /velocity/.+ + Jersey Web Application - /api-config/* - /control/* - /hello/* - /again/* - /tiny/* - /mini/* - /full/* - /velocity/* - /velocity-dev/* - /ved/* - /bwq/* - /api-config/* - /control/* + /*