Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.

Commit f35f3d3

Browse files
committed
updates files
1 parent 48122d1 commit f35f3d3

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
.idea
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Kotlin Servlet Web Application Example With Maven
2+
3+
This example is a **maven** version of **servlet-web-applications** example built using gradle.
4+
5+
Since this example illustrates the use of a REST endpoint, you will need to run this on a web application server.
6+
7+
## Prerequisites to running the example
8+
9+
* download Maven directly from the [Apache Maven homepage](http://maven.apache.org/download.html)
10+
* install and configure your system as described in [the installation section](http://maven.apache.org/download.html#Installation)
11+
12+
## Folder Structure
13+
14+
Sources
15+
16+
/src/main/kotlin
17+
18+
Build/War File
19+
20+
/target/kotlin-test-servlets.war
21+
22+
23+
## Compiling/Building the example's war file
24+
25+
If you have maven on your path, type:
26+
27+
mvn clean package
28+
29+
This will compile:
30+
* src/main/kotlin/HomeController.kt and builds a war file named **kotling-test-servlets.war** into **/target** folder
31+
32+
33+
## Running the example's war file
34+
35+
Once you compiled the sources with previous 'mvn clean package' command, you can see the 'war' file under '/target' folder.
36+
37+
Now copy the 'war' file and deploy to any web application server like Tomcat, Jetty etc.
38+
39+
After the deployment is done successfully, open a browser and point to a url like this
40+
41+
http://localhost:8080/kotlin-test-servlets/hello
42+
43+
You should see an output as below:
44+
45+
Hello, World!
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>org.jetbrains.kotlin.examples</groupId>
9+
<artifactId>servlet-web-applications-maven</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<packaging>war</packaging>
12+
13+
<properties>
14+
<kotlin.version>1.0.3</kotlin.version>
15+
<java.version>1.8</java.version>
16+
<junit.version>4.12</junit.version>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.jetbrains.kotlin</groupId>
23+
<artifactId>kotlin-stdlib</artifactId>
24+
<version>${kotlin.version}</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>junit</groupId>
29+
<artifactId>junit</artifactId>
30+
<version>${junit.version}</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.jetbrains.kotlin</groupId>
35+
<artifactId>kotlin-test-junit</artifactId>
36+
<version>${kotlin.version}</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>javax</groupId>
41+
<artifactId>javaee-api</artifactId>
42+
<version>7.0</version>
43+
<scope>provided</scope>
44+
</dependency>
45+
</dependencies>
46+
47+
<build>
48+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
49+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
50+
51+
<plugins>
52+
<plugin>
53+
<artifactId>kotlin-maven-plugin</artifactId>
54+
<groupId>org.jetbrains.kotlin</groupId>
55+
<version>${kotlin.version}</version>
56+
<executions>
57+
<execution>
58+
<id>compile</id>
59+
<phase>compile</phase>
60+
<goals>
61+
<goal>compile</goal>
62+
</goals>
63+
<configuration>
64+
<sourceDirs>
65+
<sourceDir>src/main/kotlin</sourceDir>
66+
<sourceDir>src/main/resources</sourceDir>
67+
</sourceDirs>
68+
</configuration>
69+
</execution>
70+
<execution>
71+
<id>test-compile</id>
72+
<phase>test-compile</phase>
73+
<goals>
74+
<goal>test-compile</goal>
75+
</goals>
76+
<configuration>
77+
<sourceDirs>
78+
<sourceDir>src/test/kotlin</sourceDir>
79+
<sourceDir>src/test/resources</sourceDir>
80+
</sourceDirs>
81+
</configuration>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-compiler-plugin</artifactId>
88+
<version>3.5.1</version>
89+
<configuration>
90+
<source>${java.version}</source>
91+
<target>${java.version}</target>
92+
</configuration>
93+
</plugin>
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-war-plugin</artifactId>
97+
<version>2.6</version>
98+
<configuration>
99+
<warName>kotlin-test-servlets</warName>
100+
<failOnMissingWebXml>false</failOnMissingWebXml>
101+
</configuration>
102+
</plugin>
103+
</plugins>
104+
</build>
105+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.jetbrains.kotlin.demo
2+
3+
import javax.servlet.annotation.WebServlet
4+
import javax.servlet.http.HttpServlet
5+
import javax.servlet.http.HttpServletRequest
6+
import javax.servlet.http.HttpServletResponse
7+
8+
@WebServlet(name = "Hello", value = "/hello")
9+
class HomeController : HttpServlet() {
10+
override fun doGet(req: HttpServletRequest, res: HttpServletResponse) {
11+
res.writer.write("Hello, World!")
12+
}
13+
}

0 commit comments

Comments
 (0)