Skip to content

Commit be34fd6

Browse files
Merge pull request #122 from nextmv-io/merschformann/java-multi-file-excel
Adds java gurobi multi excel file example
2 parents 77e8312 + 4bfea8a commit be34fd6

19 files changed

Lines changed: 827 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mvn package

.nextmv/readme/java-gurobi-multiknapsack-multiexcel/0.sh.golden

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java -jar main.jar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nextmv push -a <your-app-id>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nextmv run -a <your-app-id> -s <your-secret-id> -i inputs/ --content-type multi-file
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mvn package | docker run -i --rm \
2+
-v $(pwd):/app ghcr.io/nextmv-io/runtime/java:latest \
3+
java -jar /app/main.jar

.nextmv/readme/workflow-configuration.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ apps:
4040
skip: true
4141
- name: 3.sh
4242
skip: true
43+
- name: java-gurobi-multiknapsack-multiexcel
44+
scripts:
45+
- name: 0.sh
46+
silent: true
47+
# We cannot run Java Gurobi without a license, so we skip these tests.
48+
- name: 1.sh
49+
skip: true
50+
- name: 2.sh
51+
skip: true
52+
- name: 3.sh
53+
skip: true
54+
- name: 4.sh
55+
skip: true
4356
- name: java-hexaly-knapsack
4457
scripts:
4558
# Without the license and no maven package, we cannot run the tests.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/go
3+
{
4+
"name": "Java",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "ghcr.io/nextmv-io/runtime/java:latest",
7+
"features": {
8+
"ghcr.io/devcontainers/features/java:1": {
9+
"installMaven": "true",
10+
"jdkDistro": "tem",
11+
"version": "21"
12+
}
13+
},
14+
"workspaceMount": "source=${localWorkspaceFolder}/.,target=/app,type=bind",
15+
"workspaceFolder": "/app",
16+
"mounts": [
17+
"source=${localEnv:HOME}${localEnv:USERPROFILE}/gurobi.lic,target=/root/gurobi.lic,type=bind,consistency=cached"
18+
],
19+
"containerEnv": {
20+
"GRB_LICENSE_FILE": "/root/gurobi.lic"
21+
}
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
gurobi.lic
2+
.vscode/
3+
main.jar
4+
target/
5+
*.xlsx
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Nextmv Java Gurobi Multi-Knapsack
2+
3+
Example for running a Java `Maven` application on the Nextmv Platform using the
4+
Gurobi solver. We solve a multi-knapsack Mixed Integer Programming problem while
5+
reading the input from an _Excel_ file and writing the output to an _Excel_
6+
file.
7+
8+
1. Setup license:
9+
1. **Local**:
10+
- You can simply place the `gurobi.lic` file in your _home directory_
11+
(like Gurobi expects it). If you are using the dev container, it will be
12+
mounted inside of the container for you.
13+
1. **Platform**: Don't forget to also define the license file as a
14+
[secret][secret] in your Nextmv Application as well. This can be easily
15+
done via [console].
16+
- Define a file secret with the name `gurobi.lic` and the content of
17+
your license file.
18+
- Define an environment variable secret with the name `GRB_LICENSE_FILE`
19+
and the value `./gurobi.lic` to point Gurobi to the license file.
20+
1. Generate a `main.jar`.
21+
22+
```bash
23+
mvn package
24+
```
25+
26+
1. Run the app (update the input in `inputs/input.xlsx` or point to a different
27+
directory via `-input` option).
28+
29+
```bash
30+
java -jar main.jar
31+
```
32+
33+
1. If above steps were successful, you can push the app to the Nextmv Platform.
34+
E.g., using the [Nextmv CLI][install-cli]:
35+
36+
```bash
37+
nextmv push -a <your-app-id>
38+
```
39+
40+
1. You can now run the app on the Nextmv Platform by using the [Nextmv
41+
Console][console] or via the [Nextmv CLI][install-cli]:
42+
43+
```bash
44+
nextmv run -a <your-app-id> -s <your-secret-id> -i inputs/ --content-type multi-file
45+
```
46+
47+
## Mirror running on Nextmv Cloud locally
48+
49+
Docker needs to be installed.
50+
51+
To run the application in the same Docker image as the one used on Nextmv
52+
Cloud, you can use the following command:
53+
54+
```bash
55+
mvn package | docker run -i --rm \
56+
-v $(pwd):/app ghcr.io/nextmv-io/runtime/java:latest \
57+
java -jar /app/main.jar
58+
```
59+
60+
You can also debug the application by running it in a Dev Container. This
61+
workspace recommends to install the Dev Container extension for VSCode. If you
62+
have the extension installed, you can open the workspace in a container by using
63+
the command `Dev Containers: Reopen in Container`.
64+
65+
## Next steps
66+
67+
- Open `src/main/java/com/nextmv/example/Main.java` and modify the model.
68+
- Visit our [docs][docs] and [blog][blog]. Need more assistance?
69+
[Contact][contact] us!
70+
71+
[docs]: https://docs.nextmv.io
72+
[console]: https://cloud.nextmv.io
73+
[secret]: https://www.nextmv.io/docs/using-nextmv/reference/secret-collections
74+
[install-cli]: https://docs.nextmv.io/docs/using-nextmv/setup/install#nextmv-cli
75+
[blog]: https://www.nextmv.io/blog
76+
[contact]: https://www.nextmv.io/contact

0 commit comments

Comments
 (0)