From 884bc2681c9e4b975fe93cdc01d486a47522e402 Mon Sep 17 00:00:00 2001 From: Thibaut de Saivre <thibaut.de-saivre@polytechnique.edu> Date: Tue, 17 Oct 2023 15:01:23 +0200 Subject: [PATCH] add base java program and run config for linux --- java/.gitignore | 2 ++ java/.vscode/extensions.json | 6 ++++++ java/.vscode/settings.json | 14 ++++++++++++++ java/Makefile | 30 ++++++++++++++++++++++++++++++ java/README.md | 2 ++ java/src/Lib.java | 7 +++++++ java/src/Main.java | 9 +++++++++ 7 files changed, 70 insertions(+) create mode 100644 java/.gitignore create mode 100644 java/.vscode/extensions.json create mode 100644 java/.vscode/settings.json create mode 100644 java/Makefile create mode 100644 java/README.md create mode 100644 java/src/Lib.java create mode 100644 java/src/Main.java diff --git a/java/.gitignore b/java/.gitignore new file mode 100644 index 0000000..7ad426f --- /dev/null +++ b/java/.gitignore @@ -0,0 +1,2 @@ +# Ignore the output directory +out/ \ No newline at end of file diff --git a/java/.vscode/extensions.json b/java/.vscode/extensions.json new file mode 100644 index 0000000..8c2f730 --- /dev/null +++ b/java/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "vscjava.vscode-java-pack", // Extension pack for java (language server, linter, formatter...) + "vscjava.vscode-gradle" // Gradle support (if you intend to work on gradle projects, like Minecraft mods) + ] +} diff --git a/java/.vscode/settings.json b/java/.vscode/settings.json new file mode 100644 index 0000000..49b2e49 --- /dev/null +++ b/java/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + // Generic settings : + "editor.formatOnSave": true, // Format files on save + "formatFiles.runOrganizeImports": true, // Sort imports when formatting + "editor.codeActionsOnSave": { + // Organize imports on save + "source.organizeImports": true + }, + + // Java + "[java]": { + "editor.defaultFormatter": "redhat.java" + } +} diff --git a/java/Makefile b/java/Makefile new file mode 100644 index 0000000..1e60055 --- /dev/null +++ b/java/Makefile @@ -0,0 +1,30 @@ + +# Output and source directories +SOURCE_DIR = src +OUTPUT_DIR = out + +# Main source and class files +SRC_FILE = Main.java +CLASS_FILE = Main.class + +# Java compiler and interpreter paths +JAVAC = javac +JAVA = java + +.PHONY: all compile run clean + +# "make" will compile and run the program +all: compile run + +# "make compile" will compile the program +compile: + $(JAVAC) -sourcepath $(SOURCE_DIR) -d $(OUTPUT_DIR) $(SOURCE_DIR)/$(SRC_FILE) + +# "make run" will clear the terminal and run the program +run: + clear + $(JAVA) -classpath $(OUTPUT_DIR) $(basename $(SRC_FILE)) + +# "make clean" will remove the output directory's contents +clean: + rm -rf $(OUTPUT_DIR)/* \ No newline at end of file diff --git a/java/README.md b/java/README.md new file mode 100644 index 0000000..68146f6 --- /dev/null +++ b/java/README.md @@ -0,0 +1,2 @@ +TODO: quel output pour java + commandes avec vscode +TODO: pour Linux VSCode avec le makefile, sinon faire à la main diff --git a/java/src/Lib.java b/java/src/Lib.java new file mode 100644 index 0000000..2dc3fef --- /dev/null +++ b/java/src/Lib.java @@ -0,0 +1,7 @@ +/** Dependency functions */ +public class Lib { + /** Print a message to stdout */ + public static void sayMessage(String message) { + System.out.println(message); + } +} diff --git a/java/src/Main.java b/java/src/Main.java new file mode 100644 index 0000000..bef0508 --- /dev/null +++ b/java/src/Main.java @@ -0,0 +1,9 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + + String message = "This is a message"; + + Lib.sayMessage(message); + } +} \ No newline at end of file -- GitLab