Spaces:
Sleeping
Sleeping
KevanSoon
commited on
Commit
·
366df66
1
Parent(s):
f3bb92a
Javalin setup
Browse files- Dockerfile +2 -13
- pom.xml +30 -21
- src/DemoApplication.java +15 -0
- src/User.java +9 -0
- src/main/java/com/example/demo/DemoApplication.java +0 -20
- src/main/java/com/example/demo/User.java +0 -19
- target/classes/com/example/demo/DemoApplication.class +0 -0
- target/classes/com/example/demo/User.class +0 -0
- target/maven-archiver/pom.properties +0 -3
- target/springboot-hf-0.0.1-SNAPSHOT.jar +0 -0
- target/springboot-hf-0.0.1-SNAPSHOT.jar.original +0 -0
Dockerfile
CHANGED
|
@@ -1,16 +1,5 @@
|
|
| 1 |
-
FROM maven:3.9.4-eclipse-temurin-17 AS build
|
| 2 |
-
WORKDIR /app
|
| 3 |
-
|
| 4 |
-
# Copy pom and source code
|
| 5 |
-
COPY pom.xml .
|
| 6 |
-
COPY src ./src
|
| 7 |
-
|
| 8 |
-
# Build the jar
|
| 9 |
-
RUN mvn clean package -DskipTests
|
| 10 |
-
|
| 11 |
-
# Run stage
|
| 12 |
FROM eclipse-temurin:17-jre
|
| 13 |
WORKDIR /app
|
| 14 |
-
COPY
|
| 15 |
-
EXPOSE
|
| 16 |
ENTRYPOINT ["java", "-jar", "app.jar"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM eclipse-temurin:17-jre
|
| 2 |
WORKDIR /app
|
| 3 |
+
COPY target/javalin-demo-0.0.1-SNAPSHOT.jar app.jar
|
| 4 |
+
EXPOSE 7860
|
| 5 |
ENTRYPOINT ["java", "-jar", "app.jar"]
|
pom.xml
CHANGED
|
@@ -1,46 +1,55 @@
|
|
| 1 |
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
| 2 |
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| 3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
| 4 |
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| 5 |
<modelVersion>4.0.0</modelVersion>
|
| 6 |
<groupId>com.example</groupId>
|
| 7 |
-
<artifactId>demo</artifactId>
|
| 8 |
<version>0.0.1-SNAPSHOT</version>
|
| 9 |
-
<packaging>jar</packaging>
|
| 10 |
-
|
| 11 |
-
<name>springboot-hf</name>
|
| 12 |
-
<description>Spring Boot HF Space Example</description>
|
| 13 |
-
|
| 14 |
-
<parent>
|
| 15 |
-
<groupId>org.springframework.boot</groupId>
|
| 16 |
-
<artifactId>spring-boot-starter-parent</artifactId>
|
| 17 |
-
<version>3.2.5</version>
|
| 18 |
-
<relativePath/>
|
| 19 |
-
</parent>
|
| 20 |
-
|
| 21 |
<properties>
|
| 22 |
<java.version>17</java.version>
|
| 23 |
</properties>
|
| 24 |
|
| 25 |
<dependencies>
|
| 26 |
-
<!--
|
| 27 |
<dependency>
|
| 28 |
-
<groupId>
|
| 29 |
-
<artifactId>
|
|
|
|
| 30 |
</dependency>
|
| 31 |
-
|
| 32 |
-
<!--
|
| 33 |
<dependency>
|
| 34 |
<groupId>com.fasterxml.jackson.core</groupId>
|
| 35 |
<artifactId>jackson-databind</artifactId>
|
|
|
|
| 36 |
</dependency>
|
| 37 |
</dependencies>
|
| 38 |
|
| 39 |
<build>
|
| 40 |
<plugins>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
<plugin>
|
| 42 |
-
<groupId>org.
|
| 43 |
-
<artifactId>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
</plugin>
|
| 45 |
</plugins>
|
| 46 |
</build>
|
|
|
|
| 1 |
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
| 2 |
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| 3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
| 4 |
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| 5 |
<modelVersion>4.0.0</modelVersion>
|
| 6 |
<groupId>com.example</groupId>
|
| 7 |
+
<artifactId>javalin-demo</artifactId>
|
| 8 |
<version>0.0.1-SNAPSHOT</version>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
<properties>
|
| 10 |
<java.version>17</java.version>
|
| 11 |
</properties>
|
| 12 |
|
| 13 |
<dependencies>
|
| 14 |
+
<!-- Javalin -->
|
| 15 |
<dependency>
|
| 16 |
+
<groupId>io.javalin</groupId>
|
| 17 |
+
<artifactId>javalin-bundle</artifactId>
|
| 18 |
+
<version>5.6.1</version>
|
| 19 |
</dependency>
|
| 20 |
+
|
| 21 |
+
<!-- JSON serialization -->
|
| 22 |
<dependency>
|
| 23 |
<groupId>com.fasterxml.jackson.core</groupId>
|
| 24 |
<artifactId>jackson-databind</artifactId>
|
| 25 |
+
<version>2.16.4</version>
|
| 26 |
</dependency>
|
| 27 |
</dependencies>
|
| 28 |
|
| 29 |
<build>
|
| 30 |
<plugins>
|
| 31 |
+
<!-- Package JAR -->
|
| 32 |
+
<plugin>
|
| 33 |
+
<groupId>org.apache.maven.plugins</groupId>
|
| 34 |
+
<artifactId>maven-compiler-plugin</artifactId>
|
| 35 |
+
<version>3.11.0</version>
|
| 36 |
+
<configuration>
|
| 37 |
+
<source>${java.version}</source>
|
| 38 |
+
<target>${java.version}</target>
|
| 39 |
+
</configuration>
|
| 40 |
+
</plugin>
|
| 41 |
+
|
| 42 |
<plugin>
|
| 43 |
+
<groupId>org.apache.maven.plugins</groupId>
|
| 44 |
+
<artifactId>maven-jar-plugin</artifactId>
|
| 45 |
+
<version>3.3.0</version>
|
| 46 |
+
<configuration>
|
| 47 |
+
<archive>
|
| 48 |
+
<manifest>
|
| 49 |
+
<mainClass>DemoApplication</mainClass>
|
| 50 |
+
</manifest>
|
| 51 |
+
</archive>
|
| 52 |
+
</configuration>
|
| 53 |
</plugin>
|
| 54 |
</plugins>
|
| 55 |
</build>
|
src/DemoApplication.java
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io.javalin.Javalin;
|
| 2 |
+
|
| 3 |
+
public class DemoApplication {
|
| 4 |
+
|
| 5 |
+
public static void main(String[] args) {
|
| 6 |
+
// Hugging Face provides the port via environment variable
|
| 7 |
+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
|
| 8 |
+
|
| 9 |
+
Javalin app = Javalin.create().start(port);
|
| 10 |
+
|
| 11 |
+
app.get("/user", ctx -> {
|
| 12 |
+
ctx.json(new User("Kevan", 21));
|
| 13 |
+
});
|
| 14 |
+
}
|
| 15 |
+
}
|
src/User.java
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
public class User {
|
| 2 |
+
public String name;
|
| 3 |
+
public int age;
|
| 4 |
+
|
| 5 |
+
public User(String name, int age) {
|
| 6 |
+
this.name = name;
|
| 7 |
+
this.age = age;
|
| 8 |
+
}
|
| 9 |
+
}
|
src/main/java/com/example/demo/DemoApplication.java
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
package com.example.demo;
|
| 2 |
-
|
| 3 |
-
import org.springframework.boot.SpringApplication;
|
| 4 |
-
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
| 5 |
-
import org.springframework.web.bind.annotation.GetMapping;
|
| 6 |
-
import org.springframework.web.bind.annotation.RestController;
|
| 7 |
-
|
| 8 |
-
@SpringBootApplication
|
| 9 |
-
@RestController
|
| 10 |
-
public class DemoApplication {
|
| 11 |
-
|
| 12 |
-
@GetMapping("/user")
|
| 13 |
-
public User getUser() {
|
| 14 |
-
return new User("Kevan", 21);
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
public static void main(String[] args) {
|
| 18 |
-
SpringApplication.run(DemoApplication.class, args);
|
| 19 |
-
}
|
| 20 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/main/java/com/example/demo/User.java
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
package com.example.demo;
|
| 2 |
-
|
| 3 |
-
public class User {
|
| 4 |
-
private String name;
|
| 5 |
-
private int age;
|
| 6 |
-
|
| 7 |
-
public User() {}
|
| 8 |
-
|
| 9 |
-
public User(String name, int age) {
|
| 10 |
-
this.name = name;
|
| 11 |
-
this.age = age;
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
public String getName() { return name; }
|
| 15 |
-
public void setName(String name) { this.name = name; }
|
| 16 |
-
|
| 17 |
-
public int getAge() { return age; }
|
| 18 |
-
public void setAge(int age) { this.age = age; }
|
| 19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
target/classes/com/example/demo/DemoApplication.class
DELETED
|
Binary file (1.07 kB)
|
|
|
target/classes/com/example/demo/User.class
DELETED
|
Binary file (893 Bytes)
|
|
|
target/maven-archiver/pom.properties
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
artifactId=springboot-hf
|
| 2 |
-
groupId=com.example
|
| 3 |
-
version=0.0.1-SNAPSHOT
|
|
|
|
|
|
|
|
|
|
|
|
target/springboot-hf-0.0.1-SNAPSHOT.jar
DELETED
|
Binary file (22 Bytes)
|
|
|
target/springboot-hf-0.0.1-SNAPSHOT.jar.original
DELETED
|
Binary file (1.6 kB)
|
|
|