-
-
Save charyorde/766c61416a4a40df6e20b59542a36737 to your computer and use it in GitHub Desktop.
Executable War Main
This file contains hidden or 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
// Relevant Gradle snippets | |
apply plugin: 'war' | |
configurations { | |
executableWarDeps | |
} | |
dependencies { | |
// your stuff | |
executableWarDeps 'org.mortbay.jetty:jetty:6.1.4' | |
executableWarDeps 'org.codehaus.groovy:groovy-all:1.8.6' | |
} | |
war { | |
from {configurations.executableWarDeps.collect { | |
it.isDirectory() ? it : project.zipTree(it) | |
} | |
} | |
from "$buildDir/classes/main" | |
manifest { attributes 'Main-Class': 'mypackage.ExecutableMain' } | |
} |
This file contains hidden or 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
package mypackage; | |
import java.net.URL; | |
import java.security.ProtectionDomain | |
import org.mortbay.jetty.Connector; | |
import org.mortbay.jetty.Server; | |
import org.mortbay.jetty.nio.SelectChannelConnector; | |
import org.mortbay.jetty.webapp.WebAppContext; | |
/** | |
* Simple executable main, with just a dash of Groovy | |
* | |
*/ | |
class ExecutableMain { | |
static main(args) { | |
Server server = new Server(); | |
Connector connector = new SelectChannelConnector(); | |
connector.setPort(8888); | |
connector.setHost("127.0.0.1"); | |
server.addConnector(connector); | |
server.setStopAtShutdown(true); | |
WebAppContext context = new WebAppContext(); | |
context.setServer(server); | |
context.setContextPath("/"); | |
ProtectionDomain protectionDomain = DataImporterMain.class.getProtectionDomain(); | |
URL location = protectionDomain.getCodeSource().getLocation(); | |
context.setWar(location.toExternalForm()); | |
println "WAR URL: ${location.toExternalForm()}" | |
server.addHandler(context); | |
try { | |
server.start(); | |
System.in.read(); | |
server.stop(); | |
server.join(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
System.exit(100); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment