diff --git a/README.md b/README.md new file mode 100644 index 0000000..8d7640e --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# sparkjava-war-example +Build war with maven and sparkjava framework + +Steps: + +1. Download a fresh [Tomcat 8 distribution](https://tomcat.apache.org/download-80.cgi) +2. Clone this repository to your local machine +3. Run mvn package +4. Copy the generated `sparkjava-hello-world-1.0.war` to the Tomcat `webapps` folder +5. Start Tomcat by running `bin\startup.bat` (or `bin\startaup.sh` for Linux) +5. Tomcat will automatically deploy the war +6. Open [http://localhost:8080/sparkjava-hello-world-1.0/hello](http://localhost:8080/sparkjava-hello-world-1.0/hello) in your browser diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f55768d --- /dev/null +++ b/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + sparkjava-hello-world + sparkjava-hello-world + 1.0 + war + + + + com.sparkjava + spark-core + 2.7.2 + + + org.slf4j + slf4j-simple + 1.7.25 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + true + true + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.3.1 + + + enforce-java + + enforce + + + + + [1.8,) + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/HelloWorld.java b/src/main/java/HelloWorld.java new file mode 100644 index 0000000..2f1fbd8 --- /dev/null +++ b/src/main/java/HelloWorld.java @@ -0,0 +1,14 @@ +import spark.servlet.SparkApplication; + +import static spark.Spark.get; + +public class HelloWorld implements SparkApplication { + public static void main(String[] args) { + new HelloWorld().init(); + } + + @Override + public void init() { + get("/hello", (req, res) -> "Hello World"); + } +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..580d807 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + SparkFilter + spark.servlet.SparkFilter + + applicationClass + HelloWorld + + + + + SparkFilter + /* + + \ No newline at end of file diff --git a/test b/test deleted file mode 100644 index a6525f9..0000000 --- a/test +++ /dev/null @@ -1 +0,0 @@ -this is test file for java project