Skip to content

Instantly share code, notes, and snippets.

@MMcM
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MMcM/0eccc83871df4d07923a to your computer and use it in GitHub Desktop.
Save MMcM/0eccc83871df4d07923a to your computer and use it in GitHub Desktop.
Converting JBoss application to use shared FDB to avoid api_version_already_set

Converting to shared FDB

  • Find the system modules directory, which is something like $JBOSS_HOME/modules or .../jboss-eap/modules/system/layers/base/.

  • Add a new directory com/foundationdb/main there. (There should already be com and org or you probably don't have the right starting directory.)

  • Put the module.xml file into that new directory.

  • Copy fdb-java-2.0.8.jar into the same directory. (If you still have a build area from before, it will be in target/appname/WEB-INF/lib.)

  • Change the pom to have <scope>provided</scope> so that the .jar is not duplicated in the .war.

  • Add a src/main/webapp/WEB-INF/jboss-deployment-structure.xml to reference the system module.

  • Commands like mvn jboss-as:deploy and redeploy should work now.

<!-- Marker file indicating CDI should be enabled -->
<beans 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/beans_1_0.xsd">
</beans>
package com.foundationdb.jboss;
import com.foundationdb.Database;
import com.foundationdb.FDB;
import com.foundationdb.Transaction;
import com.foundationdb.async.Function;
public class FDBService {
private FDB fdb;
private Database db;
public FDBService() {
fdb = FDB.selectAPIVersion(200);
db = fdb.open();
}
public String getValue(final String key) {
return db.run(new Function<Transaction,String>() {
@Override
public String apply(Transaction tr) {
byte[] value = tr.get(key.getBytes()).get();
if (value != null) {
return new String(value);
}
else {
return "Not found";
}
}
});
}
}
package com.foundationdb.jboss;
import java.io.IOException;
import java.io.PrintWriter;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/HelloFDB")
public class HelloFDBServlet extends HttpServlet {
static String PAGE_HEADER = "<html><head><title>Hello FDB</title></head><body>";
static String PAGE_FOOTER = "</body></html>";
@Inject
FDBService fdbService;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println(PAGE_HEADER);
writer.println("<code>" + fdbService.getValue("foo") + "</code>");
writer.println(PAGE_FOOTER);
writer.close();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.foundationdb"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.foundationdb">
<properties>
<property name="jboss.api" value="unsupported"/>
</properties>
<resources>
<resource-root path="fdb-java-2.0.8.jar"/>
</resources>
</module>
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foundationdb</groupId>
<artifactId>jboss-hello-fdb</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>JBoss Hello FDB</name>
<description>JBoss FDB Integration Example</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>
<version.jboss.spec.javaee.6.0>3.0.2.Final-redhat-7</version.jboss.spec.javaee.6.0>
<version.war.plugin>2.1.1</version.war.plugin>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${version.jboss.spec.javaee.6.0}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.foundationdb</groupId>
<artifactId>fdb-java</artifactId>
<version>2.0.8</version>
<!-- See WEB-INF/jboss-deployment-structure.xml. -->
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${version.jboss.maven.plugin}</version>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment