Skip to content

Commit

Permalink
add startup
Browse files Browse the repository at this point in the history
  • Loading branch information
houxinlin committed Apr 12, 2023
1 parent 851fb06 commit 9b5f349
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ HELP.md
.gradle
build/
work/

bin/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

group = "com.hxl"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

val CooldesktopRoot = layout.projectDirectory.toString()

configurations {
Expand Down
52 changes: 52 additions & 0 deletions desktop-startup/src/main/java/com/hxl/desktop/Startup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.hxl.desktop;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;

public class Startup {
private static final String DESKTOP_NAME = "/cooldesktop/CoolDesktop.jar";
private static final String JRE_HOME = "/jre";
private static final Logger logger = Logger.getLogger(Startup.class.getSimpleName());

private static Integer toInt(String value) {
try {
return Integer.valueOf(value);
} catch (Exception e) {
}
return 0;
}
public static void main(String[] args) throws IOException {
String javaVersion = System.getProperty("java.version");
String javaHome = System.getProperty("java.home");

List<Integer> versionList = Arrays.stream(javaVersion.split("\\."))
.map(Startup::toInt)
.collect(Collectors.toList());

File file = new File(Startup.class.getProtectionDomain().getCodeSource().getLocation().getFile());
String home = file.getParent();

if (versionList.get(0) < 11) {
javaHome = Paths.get(home, JRE_HOME).toString();
}

Path desktopPath = Paths.get(home, DESKTOP_NAME);
if (!Files.exists(desktopPath)) {
logger.info("目录不存在:" + desktopPath);
System.exit(-1);
}
new ProcessBuilder()
.command(javaHome + "/bin/java", "-jar", desktopPath.toString())
.redirectOutput(new File(home + "/log/cooldesktop.log"))
.directory(new File(home))
.start();
logger.info("启动成功");
}
}
28 changes: 25 additions & 3 deletions desktop-web/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
repositories {
mavenCentral()
}
dependencies{
dependencies {
implementation(project(":desktop-file"))
implementation(project(":desktop-loader"))
implementation(project(":desktop-database"))
implementation(project(":desktop-websocket"))
implementation(project(":desktop-system"))
}

tasks.jar{
tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

}
tasks.bootJar {
destinationDirectory.set(file("../bin/cooldesktop"))
archiveFileName.set("CoolDesktop.jar")
}
tasks.register("install") {
delete( project.rootDir.toString()+"/bin/jre")
dependsOn(":desktop-startup:jar")
dependsOn(":desktop-web:bootJar")

exec {
commandLine("/home/LinuxWork/app/developer-apps/java/jdk/jdk-11.0.18/bin/jlink",
"--no-header-files",
"--no-man-pages",
"--compress=2",
"--strip-debug",
"--add-modules",
"java.base,java.desktop,java.logging,java.management,java.naming,java.net.http,java.scripting,java.security.jgss,java.security.sasl,jdk.unsupported",
"--output",
project.rootDir.toString()+"/bin/jre")
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ include("desktop-database")
include("desktop-common")
include("desktop-websocket")
include("desktop-system")
include("desktop-startup")

0 comments on commit 9b5f349

Please sign in to comment.