KevanSoon commited on
Commit
b483a7d
·
1 Parent(s): b3ac1b6

added javalin

Browse files
DemoApplication.java DELETED
@@ -1,12 +0,0 @@
1
- import io.javalin.Javalin;
2
-
3
- public class DemoApplication {
4
- public static void main(String[] args) {
5
- int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "7860"));
6
-
7
- Javalin app = Javalin.create().start(port);
8
-
9
- app.get("/", ctx -> ctx.result("Hello from Javalin on Hugging Face!"));
10
- app.get("/ping", ctx -> ctx.result("pong"));
11
- }
12
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile CHANGED
@@ -1,25 +1,15 @@
1
- FROM openjdk:17-jdk-slim
2
-
3
  WORKDIR /app
 
 
 
4
 
5
- # Install curl first
6
- RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
7
-
8
- # Download Javalin + dependencies
9
- RUN mkdir libs && \
10
- curl -L -o libs/javalin.jar https://repo1.maven.org/maven2/io/javalin/javalin/5.6.1/javalin-5.6.1.jar && \
11
- curl -L -o libs/jetty-server.jar https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-server/11.0.15/jetty-server-11.0.15.jar && \
12
- curl -L -o libs/jetty-util.jar https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-util/11.0.15/jetty-util-11.0.15.jar && \
13
- curl -L -o libs/jetty-http.jar https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-http/11.0.15/jetty-http-11.0.15.jar && \
14
- curl -L -o libs/jetty-io.jar https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-io/11.0.15/jetty-io-11.0.15.jar && \
15
- curl -L -o libs/slf4j-simple.jar https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/2.0.7/slf4j-simple-2.0.7.jar && \
16
- curl -L -o libs/slf4j-api.jar https://repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar
17
-
18
- COPY DemoApplication.java /app/
19
-
20
- RUN javac -cp "libs/*" DemoApplication.java
21
-
22
- ENV PORT=7860
23
  EXPOSE 7860
24
-
25
- CMD ["java", "-cp", ".:libs/*", "DemoApplication"]
 
1
+ # Stage 1: Build the application with Maven
2
+ FROM maven:3.9.5-eclipse-temurin-17 AS build
3
  WORKDIR /app
4
+ COPY pom.xml .
5
+ COPY src ./src
6
+ RUN mvn clean package
7
 
8
+ # Stage 2: Create a lightweight runtime image
9
+ FROM eclipse-temurin:17-jre-alpine
10
+ WORKDIR /app
11
+ COPY --from=build /app/target/app.jar /app/app.jar
12
+ # This is the port that your Javalin application will listen on
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  EXPOSE 7860
14
+ # Run the application
15
+ ENTRYPOINT ["java", "-jar", "/app/app.jar"]
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Java Endpoint
3
- emoji: 🐨
4
- colorFrom: gray
5
- colorTo: yellow
6
  sdk: docker
7
- pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: Javalin App
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: docker
7
+ app_port: 7860
8
  ---
9
 
10
+ # Javalin Application on Hugging Face Spaces
11
+
12
+ This is a simple Javalin application running in a Docker container on Hugging Face Spaces.
demo/pom.xml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+ <modelVersion>4.0.0</modelVersion>
6
+
7
+ <groupId>com.example</groupId>
8
+ <artifactId>javalin-on-huggingface</artifactId>
9
+ <version>1.0-SNAPSHOT</version>
10
+
11
+ <properties>
12
+ <maven.compiler.source>17</maven.compiler.source>
13
+ <maven.compiler.target>17</maven.compiler.target>
14
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15
+ </properties>
16
+
17
+ <dependencies>
18
+ <dependency>
19
+ <groupId>io.javalin</groupId>
20
+ <artifactId>javalin</artifactId>
21
+ <version>6.1.3</version>
22
+ </dependency>
23
+ <!-- Add other dependencies here -->
24
+ </dependencies>
25
+
26
+ <build>
27
+ <plugins>
28
+ <plugin>
29
+ <groupId>org.apache.maven.plugins</groupId>
30
+ <artifactId>maven-shade-plugin</artifactId>
31
+ <version>3.5.1</version>
32
+ <configuration>
33
+ <transformers>
34
+ <transformer
35
+ implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
36
+ <mainClass>app.Main</mainClass> <!-- Make sure this is your main class -->
37
+ </transformer>
38
+ </transformers>
39
+ <filters>
40
+ <filter>
41
+ <artifact>*:*</artifact>
42
+ <excludes>
43
+ <exclude>META-INF/*.SF</exclude>
44
+ <exclude>META-INF/*.DSA</exclude>
45
+ <exclude>META-INF/*.RSA</exclude>
46
+ </excludes>
47
+ </filter>
48
+ </filters>
49
+ <!-- The final name of the shaded JAR -->
50
+ <finalName>app</finalName>
51
+ </configuration>
52
+ <executions>
53
+ <execution>
54
+ <phase>package</phase>
55
+ <goals>
56
+ <goal>shade</goal>
57
+ </goals>
58
+ </execution>
59
+ </executions>
60
+ </plugin>
61
+ </plugins>
62
+ </build>
63
+ </project>
demo/src/main/java/com/example/Main.java ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package app;
2
+
3
+ import io.javalin.Javalin;
4
+
5
+ public class Main {
6
+ public static void main(String[] args) {
7
+ Javalin app = Javalin.create()
8
+ .get("/", ctx -> ctx.result("Hello from Javalin on Hugging Face Spaces!"))
9
+ .start(7860);
10
+ }
11
+ }