Skip to content

Commit

Permalink
Set props via properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Dec 22, 2016
1 parent 00c24f5 commit 6afa067
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
13 changes: 8 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@ create_exe(){
cat > $EXE << EOF
#!/bin/sh
function usage(){
echo "Usage: \$0 <directory> [port]"
echo "Usage: \$0 <directory> [properties-file.txt]"
echo
echo "Example: \$0 my-jsp-dir/ 8000"
echo "Example: \$0 my-jsp-dir/ "
echo
echo "The default port is 8080"
echo "The properties file is a Java properties file and must come on the form:"
echo "myprop=1"
echo "your.prop=2"
echo "These will then be set as system properties"
}
if [[ \$# < 1 ]]; then
echo "Missing arguments \$#" >> /dev/stderr
echo "Missing arguments" >> /dev/stderr
usage
exit 1
fi
# use this shell script as a jar, as the jar file is embedded!
java -Dwebroot="\$1" -Dport="\$2" -jar "\$0"
java -Dwebroot="\$1" -jar "\$0" "\$2"
exit 0
EOF

Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/github/fatso83/jspviewer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
package com.github.fatso83.jspviewer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Properties;

import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.SimpleInstanceManager;
Expand Down Expand Up @@ -99,11 +101,21 @@ public static void main(String[] args) throws Exception
s = System.getProperty("port");
if(s != null && s.length() > 0) port = Integer.parseInt(s);

String webRootIndex = System.getProperty("webroot");
String currentDir = Paths.get(".").toAbsolutePath().normalize().toString();
webRootIndex = (webRootIndex != null && webRootIndex.length() > 0)? webRootIndex : currentDir;
String userDir = System.getProperty("webroot");
String webroot = (userDir != null && userDir.length() > 0)? userDir : ".";
webroot = Paths.get(webroot).toAbsolutePath().normalize().toString();

Main main = new Main(port, webRootIndex);
// load extra system properties from file
if( args.length > 0 && args[0].length() > 0 ){
FileInputStream propFile = new FileInputStream(args[0]);
Properties p = new Properties(System.getProperties());
p.load(propFile);

// set the system properties
System.setProperties(p);
}

Main main = new Main(port, webroot);
main.start();
main.waitForInterrupt();
}
Expand Down

0 comments on commit 6afa067

Please sign in to comment.