forked from docusign/code-examples-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
58 lines (51 loc) · 2.15 KB
/
App.java
File metadata and controls
58 lines (51 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.docusign;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.FileSystems;
import java.util.Collections;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
@Slf4j
@SpringBootApplication(exclude={JmxAutoConfiguration.class})
public class App {
public static void main(String[] args) throws IOException {
SpringApplication.run(App.class, args);
openHomePage();
initFileSystem();
}
private static void openHomePage() throws IOException {
// Each operating system opens web browsers differently so we need to determine the user's
// OS and open a browser to the example homepage accordingly.
Runtime rt = Runtime.getRuntime();
if (OSDetector.isMac()){
String[] arguments = { "osascript", "-e", "open location \"" + "http://localhost:8080" + "\"" };
rt.exec(arguments);
}
else if (OSDetector.isWindows()){
rt.exec("rundll32 url.dll,FileProtocolHandler " + "http://localhost:8080");
}
else if (OSDetector.isLinux()){
String [] browsers = {"firefox", "safari", "chrome", "mozilla"};
StringBuffer cmd = new StringBuffer();
for (int i=0; i<browsers.length; i++)
cmd.append( (i==0 ? "" : " || " ) + browsers[i] +" \"" + "http://localhost:8080" + "\" ");
rt.exec(new String[] { "sh", "-c", cmd.toString() });
}
}
private static void initFileSystem() {
try {
FileSystems.newFileSystem(new URI(""), Collections.emptyMap());
log.info("FileSystem initialized successfully");
} catch (Exception e) {
if (e instanceof FileSystemAlreadyExistsException) {
log.info("FileSystem is already initialized");
} else {
log.info("Retrieving the default initialize context");
FileSystems.getDefault();
}
}
}
}