Last active
May 24, 2018 20:52
-
-
Save fmbenhassine/a5b45303b0ed790a8abc to your computer and use it in GitHub Desktop.
EJB embedded container sample #lab
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 io.github.benas.labs.javaee.ejb; | |
import javax.ejb.Stateless; | |
@Stateless | |
public class CalculatorBean { | |
public int add(int a, int b) { | |
return a + b; | |
} | |
public int subtract(int a, int b) { | |
return a - b; | |
} | |
public int multiply(int a, int b) { | |
return a * b; | |
} | |
public int divide(int a, int b) { | |
return a / b; | |
} | |
public int remainder(int a, int b) { | |
return a % b; | |
} | |
} |
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 io.github.benas.labs.javaee.ejb; | |
import javax.ejb.embeddable.EJBContainer; | |
import javax.naming.NamingException; | |
public class CalculatorTest { | |
private static CalculatorBean calculator; | |
public static void main(String[] args) throws NamingException { | |
//Bootstrap the Embedded EJB Container, MBH : META-INF/ejb-jar.xml is mandatory for bootstrapping (even empty like in this case) | |
EJBContainer ejbContainer = EJBContainer.createEJBContainer(); | |
Object object = ejbContainer.getContext().lookup("java:global/ejb/CalculatorBean"); | |
calculator = (CalculatorBean) object; | |
System.out.println("calculator : 2 + 3 = " + calculator.add(2, 3)); | |
ejbContainer.close(); | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<ejb-jar 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/ejb-jar_3_0.xsd" | |
version="3.0"> | |
</ejb-jar> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<ejb-jar 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/ejb-jar_3_0.xsd" | |
version="3.0"> | |
</ejb-jar> |
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
Manifest-Version: 1.0 | |
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
<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> | |
<parent> | |
<groupId>io.github.benas.labs</groupId> | |
<artifactId>java-labs</artifactId> | |
<version>1.0</version> | |
</parent> | |
<artifactId>ejb</artifactId> | |
<version>1.0</version> | |
<packaging>ejb</packaging> | |
<name>EJB labs</name> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<openejb.version>4.6.0</openejb.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.apache.openejb</groupId> | |
<artifactId>openejb-core</artifactId> | |
<version>${openejb.version}</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-ejb-plugin</artifactId> | |
<version>2.3</version> | |
<configuration> | |
<ejbVersion>3.2</ejbVersion> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment