Created
September 18, 2014 11:44
-
-
Save lordofthejars/4da1be4e6626bfe3b212 to your computer and use it in GitHub Desktop.
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
| public class TomEEApplication { | |
| private static void startAndDeploy(Archive<?> archive) { | |
| Container container; | |
| try { | |
| Configuration configuration = new Configuration(); | |
| String tomeeDir = Files.createTempDirectory("apache-tomee").toFile().getAbsolutePath(); | |
| configuration.setDir(tomeeDir); | |
| configuration.setHttpPort(8080); | |
| container = new Container(); | |
| container.setup(configuration); | |
| final File app = new File(Files.createTempDirectory("app").toFile().getAbsolutePath()); | |
| app.deleteOnExit(); | |
| File target = new File(app, "app.war"); | |
| archive.as(ZipExporter.class).exportTo(target, true); | |
| container.start(); | |
| container.deploy("app", target); | |
| container.await(); | |
| } catch (Exception e) { | |
| throw new IllegalArgumentException(e); | |
| } | |
| registerShutdownHook(container); | |
| } | |
| private static void registerShutdownHook(final Container container) { | |
| Runtime.getRuntime().addShutdownHook(new Thread() { | |
| @Override | |
| public void run() { | |
| try { | |
| if(container != null) { | |
| container.stop(); | |
| } | |
| } catch (final Exception e) { | |
| throw new IllegalArgumentException(e); | |
| } | |
| } | |
| }); | |
| } | |
| public static void run(Class<?> ... clazzes) { | |
| run(ShrinkWrap.create(WebArchive.class).addClasses(clazzes)); | |
| } | |
| public static void run(WebArchive archive) { | |
| startAndDeploy(archive); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment