-
-
Save StalkingKillah/e986474b6885d83c7f8d to your computer and use it in GitHub Desktop.
Jetty 8, Weld (CDI), Hibernate (JPA), Jersey (JAX-RS) - Sample ContactApp
This file contains 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
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> | |
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> | |
<Set name="serverClasses"> | |
<Array type="java.lang.String"> | |
<Item> | |
-org.eclipse.jetty.servlet.ServletContextHandler.Decorator | |
</Item> | |
</Array> | |
</Set> | |
</Configure> |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<persistence version="2.0" | |
xmlns="http://java.sun.com/xml/ns/persistence" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> | |
<persistence-unit name="production"> | |
<properties> | |
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> | |
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/contactapp" /> | |
<property name="javax.persistence.jdbc.user" value="contactapp"/> | |
<property name="javax.persistence.jdbc.password" value="contactapp" /> | |
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> | |
<property name="hibernate.hbm2ddl.auto" value="create-drop"/> | |
<property name="hibernate.show_sql" value="true"/> | |
<property name="hibernate.format_sql" value="true"/> | |
</properties> | |
</persistence-unit> | |
<persistence-unit name="development"> | |
<properties> | |
<property name="javax.persistence.jdbc.driver" value="org.sqlite.JDBC" /> | |
<property name="javax.persistence.jdbc.url" value="jdbc:sqlite:contactapp.db" /> | |
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect" /> | |
<property name="hibernate.hbm2ddl.auto" value="create-drop"/> | |
<property name="hibernate.show_sql" value="true"/> | |
<property name="hibernate.format_sql" value="true"/> | |
</properties> | |
</persistence-unit> | |
</persistence> |
This file contains 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 PersistenceFactory { | |
@Produces | |
public EntityManager getEntityManager() { | |
LoggerFactory.getLogger(PersistenceFactory.class).debug("Injecting EntityManagerFactory for production PU."); | |
return Persistence.createEntityManagerFactory("production").createEntityManager(); | |
} | |
@Produces | |
@Development | |
public EntityManager getDevEntityManager() { | |
LoggerFactory.getLogger(PersistenceFactory.class).debug("Injecting EntityManagerFactory for development PU."); | |
return Persistence.createEntityManagerFactory("development").createEntityManager(); | |
} | |
} |
This file contains 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
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>rs.ursus.lab</groupId> | |
<artifactId>ContactApp</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>war</packaging> | |
<name>ContactApp</name> | |
<properties> | |
<jersey-version>1.17.1</jersey-version> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
</properties> | |
<dependencies> | |
<!--CDI Dependency--> | |
<dependency> | |
<groupId>org.jboss.weld.servlet</groupId> | |
<artifactId>weld-servlet</artifactId> | |
<version>2.0.1.Final</version> | |
</dependency> | |
<!--JPA Dependencies--> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-entitymanager</artifactId> | |
<version>4.2.2.Final</version> | |
</dependency> | |
<dependency> | |
<groupId>org.hibernate.javax.persistence</groupId> | |
<artifactId>hibernate-jpa-2.0-api</artifactId> | |
<version>1.0.1.Final</version> | |
</dependency> | |
<!--JAX-RS Dependency--> | |
<dependency> | |
<groupId>com.sun.jersey</groupId> | |
<artifactId>jersey-server</artifactId> | |
<version>${jersey-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>com.sun.jersey</groupId> | |
<artifactId>jersey-json</artifactId> | |
<version>${jersey-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>com.sun.jersey</groupId> | |
<artifactId>jersey-servlet</artifactId> | |
<version>${jersey-version}</version> | |
</dependency> | |
<!--Production mode database--> | |
<!-- <dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-java</artifactId> | |
<version>5.1.25</version> | |
</dependency>--> | |
<!--Development mode database--> | |
<dependency> | |
<groupId>org.xerial</groupId> | |
<artifactId>sqlite-jdbc</artifactId> | |
<version>3.7.2</version> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.1</version> | |
<configuration> | |
<source>1.6</source> | |
<target>1.6</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-war-plugin</artifactId> | |
<version>2.3</version> | |
<configuration> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>jetty-maven-plugin</artifactId> | |
<version>8.1.11.v20130520</version> | |
<configuration> | |
<scanIntervalSeconds>5</scanIntervalSeconds> | |
<contextXml>src/main/webapp/WEB-INF/jetty-context.xml</contextXml> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> | |
<!--Required by Weld--> | |
<listener> | |
<listener-class>org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener</listener-class> | |
</listener> | |
<listener> | |
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> | |
</listener> | |
<servlet> | |
<servlet-name>ServletAdaptor</servlet-name> | |
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> | |
<init-param> | |
<param-name>com.sun.jersey.config.property.packages</param-name> | |
<param-value>rs.ursus.lab.contactapp.rest</param-value> | |
</init-param> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>ServletAdaptor</servlet-name> | |
<url-pattern>/rest/*</url-pattern> | |
</servlet-mapping> | |
<!-- <session-config> | |
<session-timeout> | |
30 | |
</session-timeout> | |
</session-config>--> | |
<!--Required by Weld--> | |
<resource-env-ref> | |
<resource-env-ref-name>BeanManager</resource-env-ref-name> | |
<resource-env-ref-type> | |
javax.enterprise.inject.spi.BeanManager | |
</resource-env-ref-type> | |
</resource-env-ref> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment