레이블이 Java인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Java인 게시물을 표시합니다. 모든 게시물 표시

2014년 11월 26일 수요일

Cookbook application_java and workaround to the error - undefined method 'create' for nil:NilClass

These days, I developed cookbooks to deploy java web applications. To do this efficiently, need to combine some cookbooks: java, tomcat and application_java. As what they intend to do by their names, they certainly install and configure software related to java (JDK, java container server and java application).

Developing java and tomcat cookbook wasn't a big deal, but, I encountered problem with an error in case of application_java. My code was follows:
include_recipe 'java'

application 'shop-admin' do
    path '/var/shop-admin'
    repository 'http://192.168.56.170/zabbix/shop.admin.war'
    revision '1.0'
    scm_provider Chef::Provider::RemoteFile::Deploy

    java_webapp
    tomcat
end
My error message was:
...
================================================================================
Error executing action `deploy` on resource 'deploy_revision[shop-admin]'
================================================================================

NoMethodError
-------------
undefined method `create' for nil:NilClass

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/application_java/libraries/provider_remote_file_deploy.rb:53:in `action_sync'
...
The solution was to change application_java cookbook. By default, Chef Supermarket links to https://github.com/poise/application_java.

Other people who had same issue already posted and someone recommended to clone from https://github.com/jamiely/application_java
I replaced with "jamiely/application_java". After that, my war deployed well.

2012년 11월 17일 토요일

Work to downgrade Spring framework to 2.5

I was merging a module of controlling VMware virtualization into a web project (This post was not about VMware, but Spring framework). This module originally ran on spring 3.0. The web project was supposed to develop on spring 2.5. It had to be changed to run on 2.5. While I was changing, I did the following works: 

1. In Spring 3, properties were easily injected to bean class using @value annotations, but in 2.5, it had to be defined setter method for every property which needs injection (@value is not supported in 2.5)
In 3.0
class class01 {
    @Value#{contextProperties['ws.user']} 
    private username;

In 2.5
class class01 {   
    private username;

    public setUsername(Strping username) {
         this.username = username
    }

2. In Spring 3, the context component scan worked well and it didn't need to define beans in applicationContext.xml, but in 2.5, every bean had to be defined in the configuration file.
In 3.0
<context:component-scan base-package="com.xxx.xxx" />

In 2.5
<bean id="bean01" class="com.xxx.xxx.xxxx01" />
<bean id="bean02" class="com.xxx.xxx.xxxx02" />
...

3. In Spring 3, I used xml style configuration file and  PropertyPlaceholderConfigurer wasn't needed. But, In 2.5, I was returned to properties file.
In 3.0
<util:properties id="contextProperties" location="classpath:database.xml"/>
....
....
<bean id="bean01" class="com.xxx.xxx.xxxx">
    <property name="user" value="#{contextProperties['ws.user']}" />
</bean>

In 2.5
<bean class="org.springframework.beans.....PropertyPlaceholderConfigurer" >
    <property name="location" value="database.properties" />
</bean>
....
....
<bean id="bean01" class="com.xxx.xxx.xxxx">
    <property name="user" value="${db.user}" />
</bean>

4. I was stuck with an error.
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'WebServiceLocator' defined in class path resource [applicationContext.xml]: Could not resolve placeholder 'ws.user' at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
...
...

This was occurred because Spring couldn't read *.properties files. However, I was certainly defined them.

In applicationContext.xml 
<bean class="org.springframework.beans....PropertyPlaceholderConfigurer">
    <property name="locations">
         <list>            
             <value>ConfigPrd_ko.properties</value>
             <value>database.properties</value>
         </list>                            
     </property>               
</bean>

the location of PropertyPlaceholderConfigurer was its problem. It was located in the middle of configuration file. After I changed its location to the top, it was solved. The definition of PropertyPlaceholderConfigurer should be placed higher than locations of any other bean definitions.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<bean class="org.springframework.beans......PropertyPlaceholderConfigurer" >
    <property name="locations">
         <list>            
             <value>ConfigPrd_ko.properties</value>
             <value>database.properties</value>
         </list>                            
     </property>               
</bean>
...
...
<bean id=".... />
<bean id=".... />

2012년 7월 7일 토요일

Java: Unsupported major.minor version x.x


I got an error when run the a program related to vmware 5 on eclipse.
This happened after I added vmware api into my project. 

java.lang.UnsupportedClassVersionError: com/vmware/vim25/ManagedObjectReference : Unsupported major.minor version 51.0
       at java.lang.ClassLoader.defineClass1( Native Method)
       at java.lang.ClassLoader.defineClassCond( ClassLoader.java:631)
       at java.lang.ClassLoader.defineClass( ClassLoader.java:615)
       at java.security.SecureClassLoader.defineClass( SecureClassLoader.java:141)
       at java.net.URLClassLoader.defineClass( URLClassLoader.java:283)
       at java.net.URLClassLoader.access$000( URLClassLoader.java:58)
       at java.net.URLClassLoader$1.run( URLClassLoader.java:197)
       at java.security.AccessController.doPrivileged( Native Method)
       at java.net.URLClassLoader.findClass( URLClassLoader.java:190)
       at java.lang.ClassLoader.loadClass( ClassLoader.java:306)
       at sun.misc.Launcher$AppClassLoader.loadClass( Launcher.java:301)
       at java.lang.ClassLoader.loadClass( ClassLoader.java:247)
       at GetCurrentTime.( GetCurrentTime.java:60)
Exception in thread "main" 


It was nothing to do with vmware api itself.


The reason was that I installed two kind of JDKs. The one was 1.7 and the other was 1.6.  I downloaded vmware web service API and build it with JDK 1.7 to make "vim25.jar" and I forgot this. But, on the other hand, my eclipse environment was set with JDK 1.6. 


It was lower version so didn't work with that API which was built with higher one. Again, I built the api with 1.6, it finally worked well.