Skip to content

Commit 713578c

Browse files
[JAVA-35320] Enabled kotlin-jee
2 parents d0cbb91 + 84be8ff commit 713578c

File tree

13 files changed

+550
-5
lines changed

13 files changed

+550
-5
lines changed

jee-kotlin/src/main/resources/META-INF/persistence.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
99

10-
<class>com.baeldung.jeekotlin.entity.Student</class>
10+
<class>com.baeldung.kotlinjee.entity.Student</class>
1111

1212
<properties>
1313
<property name="hibernate.hbm2ddl.auto" value="create"/>

jee-kotlin/src/test/kotlin/com/baeldung/jeekotlin/StudentResourceIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.baeldung.jeekotlin;
1+
package com.baeldung.kotlinjee;
22

3-
import com.baeldung.jeekotlin.entity.Student;
3+
import com.baeldung.kotlinjee.entity.Student;
44
import org.jboss.arquillian.container.test.api.Deployment;
55
import org.jboss.arquillian.container.test.api.RunAsClient;
66
import org.jboss.arquillian.test.api.ArquillianResource;

kotlin-jee/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## JEE in Kotlin
2+
3+
This module contains articles about Java EE with Kotlin.
4+
5+
### Relevant Articles:
6+
- [Java EE Application with Kotlin](https://www.baeldung.com/kotlin/java-ee-kotlin-app)

kotlin-jee/pom.xml

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>kotlin-jee</artifactId>
6+
<name>kotlin-jee</name>
7+
<packaging>war</packaging>
8+
9+
<parent>
10+
<groupId>com.baeldung</groupId>
11+
<artifactId>kotlin-modules</artifactId>
12+
<version>1.0.0-SNAPSHOT</version>
13+
</parent>
14+
15+
<dependencyManagement>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.jboss.arquillian</groupId>
19+
<artifactId>arquillian-bom</artifactId>
20+
<version>${arquillian_core.version}</version>
21+
<scope>import</scope>
22+
<type>pom</type>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.jboss.arquillian.extension</groupId>
26+
<artifactId>arquillian-drone-bom</artifactId>
27+
<version>${arquillian-drone-bom.version}</version>
28+
<type>pom</type>
29+
<scope>import</scope>
30+
</dependency>
31+
</dependencies>
32+
</dependencyManagement>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.jetbrains.kotlin</groupId>
37+
<artifactId>kotlin-stdlib-jdk8</artifactId>
38+
<version>${kotlin.version}</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.jetbrains.kotlin</groupId>
42+
<artifactId>kotlin-test-junit</artifactId>
43+
<version>${kotlin.version}</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>jakarta.platform</groupId>
48+
<artifactId>jakarta.jakartaee-api</artifactId>
49+
<version>${jakarta.platform.version}</version>
50+
<type>jar</type>
51+
<scope>provided</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.fasterxml.jackson.core</groupId>
55+
<artifactId>jackson-annotations</artifactId>
56+
<version>${jackson.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.fasterxml.jackson.core</groupId>
60+
<artifactId>jackson-databind</artifactId>
61+
<version>${jackson.version}</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.jboss.arquillian.junit</groupId>
66+
<artifactId>arquillian-junit-container</artifactId>
67+
<version>${arquillian_core.version}</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.jboss.shrinkwrap.resolver</groupId>
72+
<artifactId>shrinkwrap-resolver-depchain</artifactId>
73+
<version>${shrinkwrap.version}</version>
74+
<type>pom</type>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.jboss.arquillian.extension</groupId>
79+
<artifactId>arquillian-rest-client-impl-jersey</artifactId>
80+
<version>${arquillian-rest-client.version}</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.jetbrains.kotlin</groupId>
84+
<artifactId>kotlin-test</artifactId>
85+
<version>${kotlin.version}</version>
86+
<scope>test</scope>
87+
</dependency>
88+
</dependencies>
89+
90+
<build>
91+
<sourceDirectory>src/main/kotlin</sourceDirectory>
92+
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
93+
94+
<plugins>
95+
<plugin>
96+
<groupId>org.jetbrains.kotlin</groupId>
97+
<artifactId>kotlin-maven-plugin</artifactId>
98+
<version>${kotlin.version}</version>
99+
<executions>
100+
<execution>
101+
<id>compile</id>
102+
<phase>compile</phase>
103+
<goals>
104+
<goal>compile</goal>
105+
</goals>
106+
</execution>
107+
<execution>
108+
<id>test-compile</id>
109+
<phase>test-compile</phase>
110+
<goals>
111+
<goal>test-compile</goal>
112+
</goals>
113+
</execution>
114+
</executions>
115+
<configuration>
116+
<jvmTarget>1.8</jvmTarget>
117+
</configuration>
118+
</plugin>
119+
120+
<plugin>
121+
<groupId>org.apache.maven.plugins</groupId>
122+
<artifactId>maven-war-plugin</artifactId>
123+
<version>${maven-war-plugin.version}</version>
124+
<configuration>
125+
<warSourceDirectory>webapp</warSourceDirectory>
126+
<warName>kotlin</warName>
127+
</configuration>
128+
</plugin>
129+
<plugin>
130+
<groupId>org.apache.maven.plugins</groupId>
131+
<artifactId>maven-compiler-plugin</artifactId>
132+
<executions>
133+
<execution>
134+
<id>default-compile</id>
135+
<phase>none</phase>
136+
</execution>
137+
<execution>
138+
<id>default-testCompile</id>
139+
<phase>none</phase>
140+
</execution>
141+
<execution>
142+
<id>compile</id>
143+
<phase>compile</phase>
144+
<goals>
145+
<goal>compile</goal>
146+
</goals>
147+
</execution>
148+
<execution>
149+
<id>testCompile</id>
150+
<phase>test-compile</phase>
151+
<goals>
152+
<goal>testCompile</goal>
153+
</goals>
154+
</execution>
155+
</executions>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
160+
<profiles>
161+
<profile>
162+
<id>wildfly-managed-arquillian</id>
163+
<activation>
164+
<activeByDefault>true</activeByDefault>
165+
</activation>
166+
<dependencies>
167+
<dependency>
168+
<groupId>org.wildfly</groupId>
169+
<artifactId>wildfly-arquillian-container-embedded</artifactId>
170+
<version>${wildfly.version}</version>
171+
</dependency>
172+
<dependency>
173+
<groupId>org.wildfly</groupId>
174+
<artifactId>wildfly-embedded</artifactId>
175+
<version>${wildfly.version}</version>
176+
<exclusions>
177+
<exclusion>
178+
<groupId>sun.jdk</groupId>
179+
<artifactId>jconsole</artifactId>
180+
</exclusion>
181+
</exclusions>
182+
</dependency>
183+
</dependencies>
184+
<build>
185+
<plugins>
186+
<!-- You need the maven dependency plugin to download locally a zip with the server,
187+
unless you provide your own, it will download under the /target directory -->
188+
<plugin>
189+
<groupId>org.apache.maven.plugins</groupId>
190+
<artifactId>maven-dependency-plugin</artifactId>
191+
<version>${maven-dependency-plugin.version}</version>
192+
<executions>
193+
<execution>
194+
<id>unpack</id>
195+
<phase>process-test-classes</phase>
196+
<goals>
197+
<goal>unpack</goal>
198+
</goals>
199+
<configuration>
200+
<artifactItems>
201+
<artifactItem>
202+
<groupId>org.wildfly</groupId>
203+
<artifactId>wildfly-dist</artifactId>
204+
<version>${wildfly-dist.version}</version>
205+
<type>zip</type>
206+
<overWrite>false</overWrite>
207+
<outputDirectory>target</outputDirectory>
208+
</artifactItem>
209+
</artifactItems>
210+
</configuration>
211+
</execution>
212+
</executions>
213+
</plugin>
214+
<plugin>
215+
<groupId>org.apache.maven.plugins</groupId>
216+
<artifactId>maven-surefire-plugin</artifactId>
217+
<version>${maven-surefire-plugin.version}</version>
218+
<configuration>
219+
<!-- Fork every test because it will launch a separate AS instance -->
220+
<forkMode>always</forkMode>
221+
<systemPropertyVariables>
222+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
223+
<jboss.home>${project.basedir}/target/wildfly-${wildfly.version}</jboss.home>
224+
<jboss.http.port>8756</jboss.http.port>
225+
<module.path>${project.basedir}/target/wildfly-${wildfly.version}/modules</module.path>
226+
</systemPropertyVariables>
227+
<redirectTestOutputToFile>false</redirectTestOutputToFile>
228+
</configuration>
229+
</plugin>
230+
</plugins>
231+
</build>
232+
</profile>
233+
<profile>
234+
<id>wildfly-remote-arquillian-disabled</id>
235+
<dependencies>
236+
<dependency>
237+
<groupId>org.jboss.resteasy</groupId>
238+
<artifactId>resteasy-client</artifactId>
239+
<version>${resteasy.version}</version>
240+
<scope>test</scope>
241+
</dependency>
242+
<dependency>
243+
<groupId>org.jboss.resteasy</groupId>
244+
<artifactId>resteasy-jaxb-provider</artifactId>
245+
<version>${resteasy.version}</version>
246+
<scope>test</scope>
247+
</dependency>
248+
<dependency>
249+
<groupId>org.jboss.resteasy</groupId>
250+
<artifactId>resteasy-json-p-provider</artifactId>
251+
<version>${resteasy.version}</version>
252+
<scope>test</scope>
253+
</dependency>
254+
<dependency>
255+
<groupId>org.wildfly.arquillian</groupId>
256+
<artifactId>wildfly-arquillian-container-remote</artifactId>
257+
<version>${wildfly.arquillian.version}</version>
258+
<scope>test</scope>
259+
</dependency>
260+
</dependencies>
261+
</profile>
262+
</profiles>
263+
264+
<properties>
265+
<wildfly.arquillian.version>2.2.0.Final</wildfly.arquillian.version>
266+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
267+
<failOnMissingWebXml>false</failOnMissingWebXml>
268+
<jakarta.platform.version>11.0.0-M1</jakarta.platform.version>
269+
270+
<kotlin.code.style>official</kotlin.code.style>
271+
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
272+
273+
<wildfly.version>8.2.1.Final</wildfly.version>
274+
<wildfly-dist.version>31.0.1.Final</wildfly-dist.version>
275+
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
276+
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
277+
<maven-war-plugin.version>3.3.0</maven-war-plugin.version>
278+
279+
<arquillian_core.version>1.4.1.Final</arquillian_core.version>
280+
<arquillian-drone-bom.version>2.0.1.Final</arquillian-drone-bom.version>
281+
<arquillian-rest-client.version>1.0.0.Alpha4</arquillian-rest-client.version>
282+
283+
<logback.version>1.1.7</logback.version>
284+
<jackson.version>2.14.0</jackson.version>
285+
286+
<resteasy.version>3.12.0.Final</resteasy.version>
287+
<shrinkwrap.version>3.1.3</shrinkwrap.version>
288+
</properties>
289+
290+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.kotlinjee.entity
2+
3+
import jakarta.persistence.*
4+
5+
@Entity
6+
data class Student constructor (
7+
8+
@SequenceGenerator(name = "student_id_seq", sequenceName = "student_id_seq", allocationSize = 1)
9+
@GeneratedValue(generator = "student_id_seq", strategy = GenerationType.SEQUENCE)
10+
@Id
11+
var id: Long?,
12+
13+
var firstName: String,
14+
15+
var lastName: String
16+
17+
) {
18+
constructor() : this(null, "", "")
19+
20+
constructor(firstName: String, lastName: String) : this(null, firstName, lastName)
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.kotlinjee.rest
2+
3+
import javax.ws.rs.ApplicationPath
4+
import javax.ws.rs.core.Application
5+
6+
@ApplicationPath("/")
7+
class ApplicationConfig : Application() {
8+
override fun getClasses() = setOf(StudentResource::class.java)
9+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.baeldung.kotlinjee.rest
2+
3+
import com.baeldung.kotlinjee.entity.Student
4+
import com.baeldung.kotlinjee.service.StudentService
5+
import javax.inject.Inject
6+
import javax.ws.rs.*
7+
import javax.ws.rs.core.MediaType
8+
import javax.ws.rs.core.Response
9+
10+
@Path("/student")
11+
open class StudentResource {
12+
13+
@Inject
14+
private lateinit var service: StudentService
15+
16+
@POST
17+
open fun create(student: Student): Response {
18+
service.create(student)
19+
return Response.ok().build()
20+
}
21+
22+
@GET
23+
@Path("/{id}")
24+
open fun read(@PathParam("id") id: Long): Response {
25+
val student = service.read(id)
26+
return Response.ok(student, MediaType.APPLICATION_JSON_TYPE).build()
27+
}
28+
29+
@PUT
30+
open fun update(student: Student): Response {
31+
service.update(student)
32+
return Response.ok(student, MediaType.APPLICATION_JSON_TYPE).build()
33+
}
34+
35+
@DELETE
36+
@Path("/{id}")
37+
open fun delete(@PathParam("id") id: Long): Response {
38+
service.delete(id)
39+
return Response.noContent().build()
40+
}
41+
42+
}

0 commit comments

Comments
 (0)