diff --git a/build.gradle b/build.gradle index 371da131..cdde3de5 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ plugins { id 'io.spring.dependency-management' version '1.1.0' id 'org.springdoc.openapi-gradle-plugin' version '1.6.0' id "io.swagger.swaggerhub" version "1.1.0" + id 'edu.sc.seis.launch4j' version '3.0.1' } group = 'stirling.software' @@ -20,6 +21,29 @@ openApi { outputFileName = "SwaggerDoc.json" } + +launch4j { + icon = "${projectDir}/src/main/resources/static/favicon.ico" + + outfile="Stirling-PDF.exe" + headerType="console" + jarTask = tasks.bootJar + + errTitle="Encountered error, Do you have Java 17?" + downloadUrl="https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.exe" + variables=["BROWSER_OPEN=true"] + jreMinVersion="17" + + mutexName="Stirling-PDF" + windowTitle="Stirling-PDF" + + messagesStartupError="An error occurred while starting Stirling-PDF" + //messagesJreNotFoundError="This application requires a Java Runtime Environment, Please download Java 17." + messagesJreVersionError="You are running the wrong version of Java, Please download Java 17." + messagesLauncherError="Java is corrupted. Please uninstall and then install Java 17." + messagesInstanceAlreadyExists="Stirling-PDF is already running." +} + dependencies { implementation 'org.springframework.boot:spring-boot-starter-web:3.1.0' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf:3.1.0' diff --git a/lauch4jConfig.xml b/lauch4jConfig.xml new file mode 100644 index 00000000..918d6eaa --- /dev/null +++ b/lauch4jConfig.xml @@ -0,0 +1,36 @@ + + + false + console + .\build\libs\S-PDF-0.10.1.jar + .\Stirling-PDF.exe + Please download Java17 + + . + normal + https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.exe + + false + false + + ./src/main/resources/static/favicon.ico + BROWSER_OPEN=true + + Stirling-PDF + Stirling-PDF + + + %JAVA_HOME%;%PATH% + false + false + 17 + + + + An error occurred while starting Stirling-PDF + This application requires a Java Runtime Environment, Please download Java 17. + You are running the wrong version of Java, Please download Java 17. + Java is corrupted. Please uninstall and then install Java 17. + Stirling-PDF is already running. + + \ No newline at end of file diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index b91f3cb8..de43b72c 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -2,10 +2,63 @@ package stirling.software.SPDF; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.awt.*; +import java.net.URI; + +import jakarta.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; @SpringBootApplication public class SPdfApplication { + + @Autowired + private Environment env; + + @PostConstruct + public void init() { + // Check if the BROWSER_OPEN environment variable is set to true + String browserOpenEnv = env.getProperty("BROWSER_OPEN"); + boolean browserOpen = browserOpenEnv != null && browserOpenEnv.equalsIgnoreCase("true"); + + if (browserOpen) { + try { + String port = env.getProperty("local.server.port"); + if(port == null || port.length() == 0) { + port="8080"; + } + String url = "http://localhost:" + port; + + String os = System.getProperty("os.name").toLowerCase(); + Runtime rt = Runtime.getRuntime(); + if (os.contains("win")) { + // For Windows + rt.exec("rundll32 url.dll,FileProtocolHandler " + url); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + public static void main(String[] args) { SpringApplication.run(SPdfApplication.class, args); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("Stirling-PDF Started."); + + String port = System.getProperty("local.server.port"); + if(port == null || port.length() == 0) { + port="8080"; + } + String url = "http://localhost:" + port; + System.out.println("Navigate to " + url); } + + } \ No newline at end of file diff --git a/src/main/resources/static/favicon.ico b/src/main/resources/static/favicon.ico new file mode 100644 index 00000000..64fc4d07 Binary files /dev/null and b/src/main/resources/static/favicon.ico differ