Adam Bien's Weblog

Wednesday May 16, 2012

Java EE and How to Specify The Unconventional With Convention Over Configuration [Free Article]

The free (registration is required) Java Magazine article Convention Over Configuration in Java EE 6 focuses on the implementation of project and stage dependent configuration with JSF, EJB, JMX, JAX-RS and CDI.

Executable Maven 3 project is included and checked-in. Feedback is, as always, highly appreciated!



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Thursday May 10, 2012

Summer Java EE Workshops

  1. 23.05, Amsterdam Airport Java EE Hacking, Without Airport. The dutch version of Airport Hacking. Seems like sold out.
  2. 26.06-27.06, Munich Java EE Summit. I will give sessions about testing, patterns, anti-patterns and a "Productivity with Joy" workshop. Last year it was sold out.
  3. 09.07-10.07, Airport Munich Java EE Bootstrap and Effective Java EE workshops. At the first day I will focus on principles and essentials needed to bootstrap a Java EE project. The second day is all about tools, approaches and tricks for effective Java EE Development. The first edition of this workshop was sold out weeks before. After scaling the venue, there are still some seats available.

Conclusion: Everything Java EE related is sold out :-)



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Friday May 04, 2012

Great Simplification With EJB [ Screencast ]

Esoteric and home grown transaction handling, as well as, manual JPA management can be replaced with a single @Stateless annotation:

In Java EE 7 you could replace a @Stateless with the ubiquitous @Transactional annotation. However, you will have to type 4 more characters for this purpose :-)

See also other screencasts at http://www.youtube.com/user/bienadam



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Friday Apr 27, 2012

Java SE Development Kit 7 (JDK)--Released For Mac OS X

Oracle releases Java SE Development Kit 7 (JDK 1.7u4) for Mac OS X. It is the first official Oracle release for Mac OS X. See Release Notes.

JAVA_HOME can be set by putting the following line into the ~/.profile file:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home"

NetBeans 7.1.2 was simultaneously released as well. Also Java FX 2.1 is available for Mac and Windows to download.



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Wednesday Apr 25, 2012

Are Servlets Thread Safe and What Is The SingleThreadModel?

The Servlet Specification JSR-315 clearly defines the web container behavior in the service (and doGet, doPost, doPut etc.) methods (2.3.3.1 Multithreading Issues, Page 9):

"A servlet container may send concurrent requests through the service method of the servlet. To handle the requests, the Servlet Developer must make adequate provisions for concurrent processing with multiple threads in the service method.

Although it is not recommended, an alternative for the Developer is to implement the SingleThreadModel interface which requires the container to guarantee that there is only one request thread at a time in the service method. A servlet container may satisfy this requirement by serializing requests on a servlet, or by maintaining a pool of servlet instances. If the servlet is part of a Web application that has been marked as distributable, the container may maintain a pool of servlet instances in each JVM that the application is distributed across.

For servlets not implementing the SingleThreadModel interface, if the service method (or methods such as doGet or doPost which are dispatched to the service method of the HttpServlet abstract class) has been defined with the synchronized keyword, the servlet container cannot use the instance pool approach, but must serialize requests through it. It is strongly recommended that Developers not synchronize the service method (or methods dispatched to it) in these circumstances because of detrimental effects on performance".

Servlets are not thread safe and you have to synchronize your code manually what usually leads to esoteric implementations.



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Monday Apr 23, 2012

A Great Set of Java EE Examples For Tomcat On Steroids (aka TomEE)

A great set of Java EE examples (REST, EntityManager, EJB, CDI, Web Services, JMS, Transactions, Security ...), created by the Tomcat EE guys

If you need more, just request an example.

Thanks Jon for the hint!



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Wednesday Apr 18, 2012

Transparent Windows (Stage) With Java FX 2

To make the main Java FX window completely transparent, you only have to set the StageStyle.TRANSPARENT and the Scene#setFill(null):


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class TransparentStage extends Application {

    @Override
    public void start(Stage stage) {
        stage.initStyle(StageStyle.TRANSPARENT);
        Text text = new Text("Transparent!");
        text.setFont(new Font(40));
        VBox box = new VBox();
        box.getChildren().add(text);
        final Scene scene = new Scene(box,300, 250);
        scene.setFill(null);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Checkout the TransparentStage sample (source code).



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Monday Apr 16, 2012

…And The Programming Language #1 is not Java, but...

C. So if you want to be a "programming cool kid", learn C. Unfortunately Java lost its #1 rank, now it is #2.

What is wrong with tiobe? It served us so well in the recent years :-).
…and I almost forgot about C and all the exciting pointers and mallocs…



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Thursday Apr 12, 2012

Arquillian Configuration For Embedded GlassFish 3.1.2 and Maven 3

Maven 3 dependencies for Arquillian integration tests with GlassFish 3.1.2 require the declaration of a few dependencies:


<project>
    <modelVersion></modelVersion>
    <groupId></groupId>
    <artifactId></artifactId>
    <version></version>
    <packaging>war</packaging>
    <name>alienfish</name>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.0.0.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.main.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
            <version>3.1.2</version>
            <scope>provided</scope>
        </dependency>        
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
            <version>1.0.0.CR3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency> 
                   
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

The missing Maven 3 parts can be easily created from CLI.
Enjoy integration testing with the Alien and the Fish :-).

[x-ray's configuration and logging subsystems were tested with Arquillian. You will also find the integration tests in the git repo (project x-ray-services, class eg. ConfigurationIT), See also page 115 "Injection and Infrastructure Testing with Aliens" in Real World Java EE Night Hacks--Dissecting the Business Tier.]



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Tuesday Apr 10, 2012

Building Java FX 2 Libraries From Source With Maven 3

  1. Get the sources: hg clone http://hg.openjdk.java.net/openjfx/2.2/master/rt. For subsequent updates use: hg pull -u
  2. Create a JavaFX profile with a pointer to the javafx 2.2. SDK. Hence not all sources are open yet, this is a necessary step:
    
    <profile>
    	<id>javafx</id>
    <activation>
    	<activeByDefault>false</activeByDefault>
    </activation>
    <properties>
    	<fx.home>[PATH TO JAVAFX INSTALLATION]/javafx-sdk2.2.0-beta/</fx.home>
    </properties>
    </profile>
    
       
  3. Execute: mvn -Pjavafx clean install
  4. You should see the following output:

    
    [INFO] javafx ............................................ SUCCESS [0.740s]
    [INFO] test-stub-toolkit ................................. SUCCESS [2.676s]
    [INFO] javafx-beans-dt ................................... SUCCESS [1.080s]
    [INFO] javafx-concurrent ................................. SUCCESS [1.385s]
    [INFO] javafx-ui-controls ................................ SUCCESS [9.607s]
    [INFO] javafx-designtime ................................. SUCCESS [0.479s]
    [INFO] javafx-ui-common .................................. SUCCESS [8.973s]
    [INFO] javafx-rt ......................................... SUCCESS [2.241s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 27.337s
    
    

  5. Pick your own fx-runtime library from: javafx-ueber-jar/target/jfxrt.jar
  6. Run tests, file bugs: Java FX Jira :-)



*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich

Meta
My Recent Book
Java One 2009/2011
...the last 150 posts
...the last 10 comments
Links
License