Saturday, May 25, 2013

Glassfish: Exception while preparing the app : Invalid resource : __pm

I thought I'd like to share this information to anyone who might be having issue with deploying a WAR application on Glassfish Server.

My case is Glassfish 3.1.2 and the error is 
Error occurred during deployment: Exception while preparing the app : Invalid resource : jdbc/login__pm 
It's something to do with glassfish-resources.xml file. If you are deploying a WAR file, it must be a web application, and you need to have glassfish-resources.xml file in your WEB-INF folder.

For other applications, this will be in your META-INF folder.

My glassfish-resources.xml looks like this and this gives me the error  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <jdbc-connection-pool 
        allow-non-component-callers="false" associate-with-thread="false" 
        connection-creation-retry-attempts="0" 
        connection-creation-retry-interval-in-seconds="10" 
        connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" 
        connection-validation-method="auto-commit" 
        datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" 
        fail-all-connections="false" idle-timeout-in-seconds="300" 
        is-connection-validation-required="false" 
        is-isolation-level-guaranteed="true" 
        lazy-connection-association="false" lazy-connection-enlistment="false" 
        match-connections="false" max-connection-usage-count="0" 
        max-pool-size="128" max-wait-time-in-millis="0" 
        name="java:app/LoginPool" non-transactional-connections="false" 
        pool-resize-quantity="5" 
        res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" 
        steady-pool-size="10" validate-atmost-once-period-in-seconds="0" 
        wrap-jdbc-objects="false">
        <property name="serverName" value="localhost"/>
        <property name="portNumber" value="3307"/>
        <property name="databaseName" value="clientdb_user"/>
        <property name="User" value="login1"/>
        <property name="Password" value="login1"/>
        <property name="URL" value="jdbc:mysql://localhost:3307/clientdb_user?zeroDateTimeBehavior=convertToNull"/>
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="create" value="true" />
        <property name="connectionAttributes" value=";create=true" />
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="java:app/jdbc/login"
         object-type="user" pool-name="java:app/LoginPool"/>
</resources>

Wednesday, January 2, 2013

Multiple Modules EJB, JPA, JAR, WAR - Maven Netbeans

I hope this can be a useful post for those who are looking to do an EAR project, with multiple modules.
First stop, using Netbeans 7.2.1 create Maven Enterprise Application, and this will give you the EAR, EJB, and WAR project. You will have one parent project which consists only one pom.xml
  1. Create a new module, a JAR project, to contain all your POJO classes, supposedly your entity classes, java classes with @Entity annotation. Nothing else, only POJO classes. Note: don't forget to include these classes in your persistence.xml file, this is where you put the persistence.xml, not anywhere else.
  2. In your EJB projects, placed all your session beans, in NetBeans, normally this has suffix "Facade". This is where the EntityManager lives. Note: don't forget to include your database dependency jar, for MySQL is something like mysql-connector-java, there is one for PostgreSQL as well. Include JAR project as dependency here.
  3. In your WAR projects, all web application files, html, css, images, resources and etc. This is where your controller files (managed beans, converters, utils, and etc) live. Note: include JAR, and EJB projects as dependencies here.
  4. Finally, your EAR projects, which is supposed to package all three modules above.
    • Your glassfish-resources.xml should be here (if you want to use application scoped resources).
    • In your EAR pom.xml, package the JAR project into a folder called "lib" or whatever name you specify in the <defaultLibBundledir/>.
    • Use option <unpack>true</unpack>.
    • List all three modules above as dependency
  5. You should be good to go

Tuesday, September 11, 2012

Installing Ubuntu 12.04 TLS on HP 530

Simply follow the tutorial from Ubuntu site

After my installation I encountered a few glitches and issues:

  1. Can't boot into Ubuntu, I have to have my USB plugged in and boot from it
  2. Unable to set up my wireless network, the wireless button on HP530 not working
  3. Unable to find my graphics driver
For issue 1:
sudo grub-install /dev/sda  

Then I modify the /boot/grub/menu.lst and change somewhere in the line "quiet splash" to "nomodeset" 

For issue 2:
sudo rfkill unblock all  

For issue 3:
Can anyone help? I can't seem to find the correct driver.

Monday, July 30, 2012

BroadLEARN Early Learning Credits

BroadLEARN™ Early Learning is a multi-award winning early childhood literacy and numeracy program which features over 300 interactive learning and assessment activities

BroadLEARN™ Early Learning encourages exploration play for your child while developing speaking, listening, reading, writing and computer skills.

My Credit:

How to obtain JTA Transaction / User Transaction from JSF Context

There are 3 ways UserTransaction can be obtained from JSF Context, ie. InitialContext object.
1. Using SessionContext or EJBContext from within your EJB implementation class. Only Bean-Managed transaction beans can have access
@Resources EJBContext context;
UserTransaction utx = (UserTransaction) context.getUserTransaction();
2. Using InitialContext from your JSF controller class or utility class using the EJB
UserTransaction utx; 
try {
    InitialContext context = new InitialContext();
    utx = (UserTransaction) context.lookup("java:comp/UserTransaction");
} catch(Exception e){} 
3. Using InitialContext from your JSF controller class or utility class using the EJB
UserTransaction utx; 
try {
    InitialContext context = new InitialContext();
    utx = (UserTransaction) context.lookup("java.transaction.UserTransaction");
} catch(Exception e){} 

Wednesday, July 25, 2012

Embedded Glassfish 3.1.2 - Arquillian compile error

If you get :
Absent Code attribute in method that is not native or abstract in class file javax/validation/constraints/Pattern$Flag
Solution: remove this dependency (if you have it)
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

Another one:
ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.
which is caused by
Error invoking ServletContainerInitializer org.apache.jasper.runtime.TldScanner
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getServletRegistration(Ljava/lang/String;)Ljavax/servlet/ServletRegistration;
 at org.apache.jasper.runtime.TldScanner.onStartup(TldScanner.java:231)
Solution is to modify your pom.xml. Tell maven-surefire-plugin to ignore servlet-api 2.3
<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>   
    <configuration>
       <forkMode>always</forkMode>
       <classpathDependencyExcludes>
           <classpathDependencyExcludes>               
               javax.servlet:servlet-api
           </classpathDependencyExcludes>
           <classpathDependencyExcludes>
               org.apache.felix:javax.servlet
           </classpathDependencyExcludes>
      <classpathDependencyExcludes>
    </configuration>
</plugin>
Taken from this site: http://java.net/jira/browse/GLASSFISH-17445