Skip to content

Commit

Permalink
make stuff work from within jar
Browse files Browse the repository at this point in the history
  • Loading branch information
ideadapt committed Dec 18, 2022
1 parent 28c62d9 commit fb77fdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Java
Build jars (fat and thin jar): `mvn -DskipTests=true clean dependency:copy-dependencies package`

## Thin jar, no Manifest
`java -classpath "target/server-1.0-SNAPSHOT.jar:target/dependency/*" ch.ibw.appl.todo.server.Main --test=true`

## Fat jar, with Manifest
This does not work with hsqldb in memory database. Hence, you require a running mysql/mariadb database.

`java -jar target/server-1.0-SNAPSHOT-jar-with-dependencies.jar`

# Docker

Build image with `docker build --tag todomvc-java-server .`
Build image `docker build --tag todomvc-java-server .`

Run built image with `docker run --rm -p 4567:4567 todomvc-java-server`
Run built image `docker run --rm -p 4567:4567 todomvc-java-server`
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.sql2o.Sql2o;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
Expand Down Expand Up @@ -35,10 +36,9 @@ public class TodoItemSQL2ORepository implements TodoItemRepository<TodoItem> {
}

private void executeFile(Connection conn, String resourcePath) {
String path = getClass().getClassLoader().getResource(resourcePath).getPath();
String content;
try {
content = new String(Files.readAllBytes(Paths.get(path)));
try (InputStream stream = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
content = new String(stream.readAllBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit fb77fdf

Please sign in to comment.