-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
desktop-startup/src/main/java/com/hxl/desktop/Startup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("启动成功"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters