Saturday, August 28, 2010

Spring IDE "Build is incomplete" and commons-logging.properties

I use sts 2.3.2 and always got "Build path is incomplete" issues. And I found this was caused by this exception:

java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AspectDefinitionMatcher.initAspectJE xpressionPointcut(AspectDefinitionMatcher.java:229 )
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AspectDefinitionMatcher.createAspect JPointcutExpression(AspectDefinitionMatcher.java:1 86)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AspectDefinitionMatcher.internalMatc hes(AspectDefinitionMatcher.java:262)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AspectDefinitionMatcher.matches(Aspe ctDefinitionMatcher.java:92)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob$1.doWith ActiveProjectClassLoader(AopReferenceModelBuilderJ ob.java:253)
at org.springframework.ide.eclipse.core.java.JdtUtils $DefaultProjectClassLoaderSupport.executeCallback( JdtUtils.java:850)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob.buildAop ReferencesForBean(AopReferenceModelBuilderJob.java :209)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob.buildAop ReferencesForBeans(AopReferenceModelBuilderJob.jav a:281)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob.buildAop ReferencesForBeansConfig(AopReferenceModelBuilderJ ob.java:307)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob.buildAop ReferencesFromBeansConfigSets(AopReferenceModelBui lderJob.java:395)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob.buildAop ReferencesForFile(AopReferenceModelBuilderJob.java :353)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob.buildAop Model(AopReferenceModelBuilderJob.java:448)
at org.springframework.ide.eclipse.aop.core.internal. model.builder.AopReferenceModelBuilderJob.run(AopR eferenceModelBuilderJob.java:157)
at org.eclipse.core.internal.jobs.Worker.run(Worker.j ava:55)
Caused by: org.apache.commons.logging.LogConfigurationExcepti on: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
at org.apache.commons.logging.impl.LogFactoryImpl.dis coverLogImplementation(LogFactoryImpl.java:874)
at org.apache.commons.logging.impl.LogFactoryImpl.new Instance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.get Instance(LogFactoryImpl.java:336)
at org.apache.commons.logging.impl.LogFactoryImpl.get Instance(LogFactoryImpl.java:310)
at org.apache.commons.logging.LogFactory.getLog(LogFa ctory.java:685)
at org.springframework.ide.eclipse.springframework.ao p.aspectj.AspectJExpressionPointcut.(Aspec tJExpressionPointcut.java:96)
... 20 more

Even upgrading to 2.3.3.M3 didn't help.

And I found org.apache.commons.logging.impl.Log4JLogger was not in
.metadata/.plugins/org.springframework.ide.eclipse.osgi.targetdefinition/2.5.0.201008251000-M3/target/com.springsource.slf4j.org.apache.commons.logging-1.5.6.jar. That explains why the exception happens.

My project uses common-logging.properties to config log4j with this line,

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

I tried to remove the dependency of common-logging, and common-logging.properties from my maven project, and cleaned all maven projects to remove common-logging.properties from target/classes and target/test-classes.

Then everything become ok. No "Build path is incomplete" any more.

Unfortunately, I couldn't reproduce it when I put common-logging.properties back to the project, and built the maven project.

I guess common-logging.properties somehow was picked by SPRING IDE.

Friday, August 27, 2010

My Cygwin/Xwin settings

This is my ~/.Xdefaults file:

Xft.dpi: 96.0
Xft.hinting: 1
Xft.rgba : rgb
Xft.antialias: 1
Xft.hintstyle: hintfull

XTerm*faceName: Bitstream Vera Sans Mono
XTerm*faceSize: 10
XTerm*scrollBar: True
XTerm*rightScrollBar: True
XTerm*renderFont: True

URxvt*background: #EFFFEF
URxvt*foreground: #000000
URxvt.font: xft:Bitstream Vera Sans Mono:size=10:light:roman:antialias=true,xft:NSimSun:size=16:medium:antialias=true
URxvt*boldFont: xft:Bitstream Vera Sans Mono:size=10:bold:roman:antialias=true,xft:SimHei:size=16:medium:antialias=true
URxvt*italicFont: xft:Bitstream Vera Sans Mono:size=10:medium:italic:autohint=true:antialias=true
URxvt*boldItalicFont: xft:Bitstream Vera Sans Mono:size=10:bold:italic:autohint=true:antialias=true
URxvt.scrollBar: True
URxvt.scrollBar_right: True
URxvt.Shading: 50
URxvt.fading: 50
URxvt.geometry:80x25

Friday, August 6, 2010

Without cropping in Cygwin Xwin during switch monitors

I have a laptop with a LCD 1400x900 and a monitor with 1280x1024 connecting to the dock. When I dock and undock the laptop, my Cygwin Xwin always has something cropped. XWin doesn't change the resolution automatically, and I cannot use xrandr to change it too. For example, after starting xwin using LCD, and docking the laptop, xrandr still returns:


bash-3.2$ xrandr -q
Screen 0: minimum 1440 x 900, current 1440 x 900, maximum 1440 x 900
default connected 1440x900+0+0 0mm x 0mm
1440x900 0.0*


and the following command will fail because the size can only be 1440x900.


bash-3.2$ xrandr -fb 1280x1024


This is annoying because I have to restart xwin after switching the monitor. Finally I found this thread solved my problem.

add the following options into /usr/bin/startx


serverargs="-screen 0 1440x1024x32 -multiwindow -clipboard"


Basically it creates a screen large enough to cover any monitor.

Thursday, August 5, 2010

Use mock_model outside of Rails

I want to use RSpec's mock_model outside of Rails, but only found this mail thread.

Actually it is not hard to use mock_model without rails. You need to install rspec-rails, and active_record gem first. Here is an example,


require 'active_support/core_ext/hash'
require 'spec/rails/mocks'
include Spec::Rails::Mocks

class TestTable
end

class View
def initialize(table)
@table = table
end

def print_keys
"name is #{@table.name} #{@table.class.primary_keys.join(",")}"
end

def print_name
"name is #{@table.name}"
end
end

describe "TestTable" do
before do
table = mock_model(TestTable, :name=>"table_abc")
@view = View.new(table)
end

it "should fail the expectation check" do
TestTable.should_receive(:primary_keys).and_return(["pk1", "pk2"])
@view.print_keys.should == "name is table_abc"
end

it "should complain that no primary_keys is called" do
TestTable.should_receive(:primary_keys).and_return(["pk1", "pk2"])
@view.print_name.should == "name is table_abc"
end

it "should print the table name" do
@view.print_name.should == "name is table_abc"
end

it "should print the table name and keys" do
TestTable.should_receive(:primary_keys).and_return(["pk1", "pk2"])
@view.print_keys.should == "name is table_abc pk1,pk2"
end
end

Monday, July 26, 2010


$ gem list gherkin cucumber
*** LOCAL GEMS ***
gherkin (2.2.0, 2.0.2)

$ gem install cucumber
ERROR: Error installing cucumber:
cucumber requires gherkin (~> 2.1.4, runtime)

The following command didn't work too
$gem install gherkin cucumber
You have to install gherkin 2.1.4 or 2.1.5 first.
$gem install gherkin --version 2.1.5

See "Specifying Versions" of RubyGems here

Thursday, July 22, 2010

Run cuke4duke from Eclipse

For a project using cuke4duke-maven-plugin, you can run integration test using Eclipse launcher, but you need to install the dependent packages into local repository. This is not convenient because you may change the dependent package in your workspace to make testes pass.

Just turn on "Resolve workspace artifacts" in "Run Configurations" dialog, and you don't have to install them.

Maven build without installing dependent packages in local repository

If you split your large project into several maven projects, and put them in sibling folders as follows:

+- parent
|
+- api
|
+- persistence
|
+- core

and core depends on api and persistence, while persistence depends on api. You can run maven command in parent/ to build them all without installing the packages into local maven repository:


parent $ mvn clean package

If you just want to build persistence, and you go to the folder core, then run maven, you will be asked to install api into repository. You can overcome this by running this command in parent folder:


parent $ mvn -o -am -pl groupId:core clean package

because all packages are in sibling folders, you may want to try this command:


parent $ mvn -o -am -pl ../core clean package

But this won't work and you may get an error message like "Couldn't find specified project in module list: M:\..\parent\..\core". Check this: MNG-4262.