Home » Archives for Sebastian Daschner » Page 10

Author Archives: Sebastian Daschner

Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.

Continuous Delivery friendly Maven versions

A Continuous Delivery pipeline requires predictable software and dependency versions. Snapshot versions, which are common in Maven software projects, contradict the motivation behind Continuous Delivery. In order to update snapshot versions to release versions developers usually edit the pom.xml file by hand or via a plugin such as the maven-release-plugin. However, Maven also offers the possibility to define version numbers ...

Read More »

Using JAX-RS exceptions for status codes

java-interview-questions-answers

One way to send specific HTTP (error) status codes from a JAX-RS resource is to use the javax.ws.rs.core.Response class with its Builder Pattern-like API. If you want to specify the return type according to the response body, you can still do so and send a different status on errors by throwing a WebApplicationException. @Path("test") public class TestResource { @GET public ...

Read More »

JPA persistence.xml SQL script definitions

java-interview-questions-answers

You can define and link to SQL scripts in a JPA persistence context definition that will be executed at runtime. There are standardized properties to define scripts how to create the schema, bulk-load data and drop the schema, respectively: <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="prod" transaction-type="JTA"> <properties> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> <property name="javax.persistence.schema-generation.create-script-source" value="create-schema.sql" /> <property name="javax.persistence.schema-generation.sql-load-script-source" value="load-data.sql" /> ...

Read More »

Access Git repositories with Java using SSH keys

For some use-cases you might access a git repository from a Java application. JGit offers a helpful integration with builder pattern APIs. The Git client can authenticate itself using SSH keys. To open a Git repository call the cloneRepository() command. File workingDir = Files.createTempDirectory("workspace").toFile(); TransportConfigCallback transportConfigCallback = new SshTransportConfigCallback(); git = Git.cloneRepository() .setDirectory(workingDir) .setTransportConfigCallback(transportConfigCallback) .setURI("ssh://example.com/repo.git") .call(); Our own implementation of ...

Read More »

WildFly Kubernetes exec probes

Liveness and readiness probes tell Kubernetes whether a pod is running and ready to do some work. An enterprise application can probe the status of an application via HTTP. If no HTTP endpoint is exposed Kubernetes can also probe by executing commands. WildFly ships with the useful jboss-cli.sh. This CLI retrieves information about the server and deployment states as follows: ...

Read More »

Jersey client dependencies for JAX-RS 2.1

java-interview-questions-answers

Jersey is the reference implementation of JAX-RS 2.1. The following Jersey dependencies are required in order to run a JAX-RS 2.1 client with JSON-P and JSON-B mapping outside of an enterprise container. Jersey client version 2.6 implements the JAX-RS 2.1 API. Following dependencies add the client runtime to a project: <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.glassfish.jersey.inject</groupId> <artifactId>jersey-hk2</artifactId> <version>2.26</version> </dependency> ...

Read More »

Dockerized Java EE 8 applications with GlassFish 5.0

GlassFish 5.0 represents the reference implementation of Java EE 8. We can dockerize Java EE 8 applications by using a GlassFish base image, such as the official oracle/glassfish. The Dockerfile of a zero-dependency Java EE 8 application looks like follows: FROM oracle/glassfish:5.0 COPY target/application.war $GLASSFISH_HOME/glassfish/domains/domain1/autodeploy/ A Docker container of that image starts the application server and auto-deploys our application. application.war ...

Read More »