|
| 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