I started a play framework project and I need to run it through the java class main method. Here is my Java Class.
import java.util.Scanner;
public class Tester {
public static void main(String[] args) {
System.out.println("Menu");
System.out.println("Press A to add");
System.out.println("Press D to Delete");
System.out.println("Press V to View");
System.out.println("Press G to Start Server");
Scanner scanner = new Scanner(System.in);
System.out.print("Please Enter Your Select: ");
String select = scanner.nextLine();
switch (select){
case "A":
// add method
break;
case "D":
// delete method
break;
case "V":
// view method
break;
case "G":
// start server
break;
default:
System.out.println("Something went wrong!");
}
}
}
What should come to the start server method???
You can try following code to open the port of active localhost server.
Desktop desktop = Desktop.getDesktop();
URI url = new URI("http://localhost:9000/");
desktop.browse(url);
Or else, if you need to access terminal commands then try this; but make sure your play project directory path. Now possibly run sbt commands inside java console using this.
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
public class Cmd {
public static void main(String[] args) throws IOException {
Process process = Runtime.getRuntime()
.exec("cmd /c dir", null, new File("C:\\Users\\"));
//.exec("sh -c ls", null, new File("Pathname")); for non-Windows users
printResults(process);
}
private static void printResults(Process process) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.