https://github.com/cchacin/tomee-boot
Apache TomEE + Shrinkwrap == JavaEE Boot
https://github.com/cchacin/tomee-boot
Last synced: 25 days ago
JSON representation
Apache TomEE + Shrinkwrap == JavaEE Boot
- Host: GitHub
- URL: https://github.com/cchacin/tomee-boot
- Owner: cchacin
- Created: 2014-10-01T20:16:00.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-11-12T22:03:27.000Z (almost 11 years ago)
- Last Synced: 2025-05-16T08:10:03.343Z (5 months ago)
- Language: Java
- Size: 172 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Apache TomEE + Shrinkwrap == JavaEE Boot
============Based on this [article](http://java.dzone.com/articles/apache-tomee-shrinkwrap-javaee) published in DZone by @lordofthejars
```xml
org.apache.openejb
tomee-embedded
1.7.1
org.apache.openejb
tomee-jaxrs
1.7.1
org.jboss.shrinkwrap
shrinkwrap-depchain
1.2.2
pom
```
```java
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;@Stateless
@Path("/sample")
public class SampleController {@GET
@Produces("text/plain")
public String sample() {
return "Hello World";
}public static void main(String args[]) {
TomEEApplication.run(SampleController.class);
}
}
``````java
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);
}
}
```