Add code to open a command window when .jar is launched

Just remember to set isEclipse to false
This commit is contained in:
Keenan D. Buckley
2019-01-18 19:44:34 -07:00
parent 2b6ee386d6
commit 0a30c9688f
6 changed files with 62 additions and 4 deletions
+1
View File
@@ -22,3 +22,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
builds/Launcher.bat builds/Launcher.bat
/.metadata/
+3
View File
@@ -0,0 +1,3 @@
@echo off
java -jar bin
exit
+3
View File
@@ -0,0 +1,3 @@
/.classpath
/.project
/robopipe/
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>src</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
+32 -4
View File
@@ -4,9 +4,13 @@
*/ */
package robopipe; package robopipe;
import java.awt.GraphicsEnvironment;
import java.io.Console;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
@@ -18,6 +22,9 @@ import edu.wpi.first.networktables.NetworkTableInstance;
public class App { public class App {
///TODO: Always remember to set to false before building
static boolean isEclipse = true;
NetworkTableEntry encoderEntry, navXEntry; NetworkTableEntry encoderEntry, navXEntry;
double encoder = 46.83583538, navX = 3.37583994; double encoder = 46.83583538, navX = 3.37583994;
ServerSocket serverSocket; ServerSocket serverSocket;
@@ -27,10 +34,31 @@ public class App {
InputStream in; InputStream in;
String output; String output;
public static void main( String[] args ) public static void main( String[] args )
{ {
System.out.println("Robopipe Start"); // Thanks to Frezze98 bolalo on StackOverflow for the code to create a batch file
new App().run(); // to start the program in a command window
Console console = System.console();
if(console == null && !GraphicsEnvironment.isHeadless() && !isEclipse) {
String filename = new File(App.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();
try {
File batch = new File("Launcher.bat");
if(!batch.exists()){
batch.createNewFile();
PrintWriter writer = new PrintWriter(batch);
writer.println("@echo off");
writer.println("java -jar "+filename);
writer.println("exit");
writer.flush();
}
Runtime.getRuntime().exec("cmd /c start \"\" "+batch.getPath());
} catch(IOException e) {
e.printStackTrace();
}
} else {
System.out.println("Robopipe Start");
new App().run();
}
} }
public void run() { public void run() {