From 55c7c8defd05aa6a795712a2fed1fd7f8e11f736 Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Fri, 26 Jan 2018 23:15:19 +0100 Subject: [PATCH] Jar compiling is now possible --- .../Minecraft_Server_Launcher_jar/run.bat | 2 + .../META-INF/MANIFEST.MF | 3 ++ src/META-INF/MANIFEST.MF | 3 ++ src/Main.java | 2 +- .../serverlauncher/server/ServerType.java | 49 ++++++++++--------- .../serverlauncher/userinterface/GUI.java | 17 ++++--- 6 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 bin/artifacts/Minecraft_Server_Launcher_jar/run.bat create mode 100644 bin/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF create mode 100644 src/META-INF/MANIFEST.MF diff --git a/bin/artifacts/Minecraft_Server_Launcher_jar/run.bat b/bin/artifacts/Minecraft_Server_Launcher_jar/run.bat new file mode 100644 index 0000000..247cf4b --- /dev/null +++ b/bin/artifacts/Minecraft_Server_Launcher_jar/run.bat @@ -0,0 +1,2 @@ +java -jar Minecraft-Server-Launcher.jar +pause \ No newline at end of file diff --git a/bin/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF b/bin/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5ee19cb --- /dev/null +++ b/bin/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Main + diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5ee19cb --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Main + diff --git a/src/Main.java b/src/Main.java index 94c1cf1..c49ccf7 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,7 +11,7 @@ import javax.naming.ConfigurationException; * @version 0.0.0.1 * @since 0.0.0.1 */ -@SuppressWarnings("SpellCheckingInspection") + class Main { public static void main(String[] args) { setup(); diff --git a/src/net/knarcraft/serverlauncher/server/ServerType.java b/src/net/knarcraft/serverlauncher/server/ServerType.java index 7fa4426..8670603 100644 --- a/src/net/knarcraft/serverlauncher/server/ServerType.java +++ b/src/net/knarcraft/serverlauncher/server/ServerType.java @@ -49,32 +49,33 @@ public class ServerType { */ public static void loadServerTypes() throws ConfigurationException { if (serverTypes.isEmpty()) { - try (Scanner in = new Scanner(new File("config/servertypes.csv"))) { - while (in.hasNextLine()) { - String[] str = in.nextLine().split(";", -1); - int len = str.length; - String[] ver; - if (str[1].contains(",")) { - ver = str[1].split(",", -1); - } else { - ver = new String[]{str[1]}; - } - switch (len) { - case 7: - new AdvancedServerType(str[0], ver, str[2], str[3], str[4], str[5], str[6]); - break; - case 3: - new ServerType(str[0], ver, str[2]); - break; - default: - throw new ConfigurationException("Error: Configuration file invalid."); - } - } + Scanner file; + try { + file = new Scanner(new File("config/servertypes.csv")); } catch (FileNotFoundException e) { - throw new ConfigurationException("Error: Configuration file not found."); - } catch (ArrayIndexOutOfBoundsException e) { - throw new ConfigurationException("Error: Configuration file invalid."); + file = new Scanner(ServerType.class.getResourceAsStream("/config/servertypes.csv")); } + + while (file.hasNextLine()) { + String[] str = file.nextLine().split(";", -1); + int len = str.length; + String[] ver; + if (str[1].contains(",")) { + ver = str[1].split(",", -1); + } else { + ver = new String[]{str[1]}; + } + switch (len) { + case 7: + new AdvancedServerType(str[0], ver, str[2], str[3], str[4], str[5], str[6]); + break; + case 3: + new ServerType(str[0], ver, str[2]); + break; + default: + throw new ConfigurationException("Error: Configuration file invalid."); + } + } } else { throw new ConfigurationException("Error: Configuration already loaded."); } diff --git a/src/net/knarcraft/serverlauncher/userinterface/GUI.java b/src/net/knarcraft/serverlauncher/userinterface/GUI.java index 88bf151..4be11f4 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/GUI.java +++ b/src/net/knarcraft/serverlauncher/userinterface/GUI.java @@ -1,8 +1,10 @@ package net.knarcraft.serverlauncher.userinterface; +import javax.imageio.ImageIO; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; +import java.io.IOException; /** * A class for creating the gui. @@ -15,18 +17,17 @@ public class GUI { public GUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (UnsupportedLookAndFeelException e) { + } catch (ClassNotFoundException | UnsupportedLookAndFeelException | InstantiationException | IllegalAccessException e) { e.printStackTrace(); } JFrame frame = new JFrame("Minecraft server launcher"); - ImageIcon img = new ImageIcon("files/GUIIcon.png"); + ImageIcon img; + try { + img = new ImageIcon(ImageIO.read(GUI.class.getResourceAsStream("/files/GUIIcon.png"))); + } catch (IOException | IllegalArgumentException e) { + img = new ImageIcon("files/GUIIcon.png"); + } frame.setIconImage(img.getImage()); frame.setLocation(0,0); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);