Created
March 22, 2014 13:57
-
-
Save slamdev/9707532 to your computer and use it in GitHub Desktop.
Embedded glassfish runner
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
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.util.Properties; | |
import java.util.logging.LogManager; | |
import org.glassfish.embeddable.Deployer; | |
import org.glassfish.embeddable.GlassFish; | |
import org.glassfish.embeddable.GlassFishProperties; | |
import org.glassfish.embeddable.GlassFishRuntime; | |
import org.glassfish.embeddable.archive.ScatteredArchive; | |
public class DevRun { | |
public static void main(String[] args) throws Exception { | |
Properties properties = new Properties(); | |
properties.setProperty("handlers", "org.slf4j.bridge.SLF4JBridgeHandler"); | |
ByteArrayOutputStream output = new ByteArrayOutputStream(); | |
properties.store(output, null); | |
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); | |
LogManager.getLogManager().readConfiguration(input); | |
try { | |
GlassFishProperties glassfishProperties = new GlassFishProperties(); | |
glassfishProperties.setPort("http-listener", 8080); | |
glassfishProperties.setPort("https-listener", 8181); | |
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); | |
glassfish.start(); | |
Deployer deployer = glassfish.getDeployer(); | |
ScatteredArchive archive = new ScatteredArchive(DevRun.class.getSimpleName(), ScatteredArchive.Type.WAR, | |
new File("src/main/webapp")); | |
archive.addClassPath(new File("target", "classes")); | |
archive.addMetadata(new File("src/main/webapp/WEB-INF", "web.xml")); | |
deployer.deploy(archive.toURI(), "--contextroot=/"); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
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
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-api</artifactId> | |
<version>1.7.6</version> | |
</dependency> | |
<dependency> | |
<groupId>ch.qos.logback</groupId> | |
<artifactId>logback-classic</artifactId> | |
<version>1.1.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>jul-to-slf4j</artifactId> | |
<version>1.7.6</version> | |
</dependency> | |
<dependency> | |
<groupId>org.glassfish.main.extras</groupId> | |
<artifactId>glassfish-embedded-all</artifactId> | |
<version>3.1.2.2</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment