今天,同僚們需要吧Liferay中的service builder切換到Maven,因為maven的archetype中已經加了maven 6.1版本,是以我以為這個問題很簡單,哪知道,這個問題足足難了我3個小時。
前面步驟都一樣,建立一個service-builder的archetype,如下圖:
<a href="http://blog.51cto.com/attachment/201206/225327279.png" target="_blank"></a>
然後在運作指令 liferay:build-service時,總出現以下問題:
資訊: Global lib directory /C:/Users/asus/.m2/repository/com/liferay/portal/portal-service/6.1.0/
2012-6-13 22:11:45 com.liferay.portal.kernel.log.Jdk14LogImpl info
資訊: Portal lib directory /C:/Users/asus/.m2/repository/com/liferay/portal/util-java/6.1.0/util-java-6.1.0.jar!/
SLF4J: The requested version 1.6.4 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/asus/.m2/repository/com/liferay/portal/util-java/6.1.0/util-java-6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/asus/.m2/repository/org/slf4j/slf4j-log4j12/1.5.11/slf4j-log4j12-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] Total time: 4:05.758s
[INFO] Finished at: Wed Jun 13 22:11:45 CST 2012
[INFO] Final Memory: 3M/15M
[ERROR] Failed to execute goal com.liferay.maven.plugins:liferay-maven-plugin:6.1.0:build-service (default-cli) on project mavensb-portlet: Execution default-cli of goal com.liferay.maven.plugins:liferay-maven-plugin:6.1.0:build-service failed: An API incompatibility was encountered while executing com.liferay.maven.plugins:liferay-maven-plugin:6.1.0:build-service: java.lang.AbstractMethodError: com.liferay.util.sl4fj.LiferayLoggerAdapter.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
原因就是slf4j,架構需要1.6.4版本的slf4j,但是隻提供了1.5.X版本的slf4j,我一開始以為這個問題很簡單,就在我們項目的<dependency>中加一些<exclusion>把低版本的slf4j排除就可以,結果無論怎樣都于事無補。我們也在Liferay官網上找了,但是有人遇到相同的問題,但是沒解決方案。
後來,我仔細回味整個過程,其實這個問題并不如我們所想象那樣簡單,雖然從日志中貌似是util-java中的某個類依賴了slf4j的1.5.X版本,其實還有一個地方依賴,就是jackrabbit,是以我們必須吧這些依賴全部正确的給他配置好才可以。
是以,我想到了去定制liferay-maven-plugin,我在C:\Users\asus\.m2\repository\com\liferay\maven\plugins\liferay-maven-plugin\6.1.0 目錄中找到了liferay-maven-plugin-6.1.0.pom ,然後把所有的依賴全部改了下,去掉舊版本的slf4j,最終,這個被我定制的pom如下所示:
我改動的部分包括204-212行,把jackrabbit中對jcl-over-slf4j的依賴移除掉:
第242-249行,移除舊版本的slf4j
第251-258行,添加新版本的slf4j
第261-268行,移除舊版本的slf4j-log4j
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>plugins</artifactId>
<groupId>com.liferay.maven</groupId>
<version>6.1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Liferay Maven 2 Plugin</name>
<version>6.1.0</version>
<description>Contains goals to manage Liferay plugins.</description>
<build>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.9</version>
<configuration>
<goalPrefix>liferay</goalPrefix>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Liferay -->
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-impl</artifactId>
<version>${liferay.version}</version>
</dependency>
<artifactId>portal-service</artifactId>
<artifactId>util-bridges</artifactId>
<artifactId>util-java</artifactId>
<!-- Maven -->
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
<artifactId>maven-model</artifactId>
<artifactId>maven-plugin-api</artifactId>
<artifactId>maven-project</artifactId>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<!-- External -->
<groupId>com.sun.media</groupId>
<artifactId>jai-codec</artifactId>
<version>1.1.3</version>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
<version>1.12</version>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.4</version>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<groupId>easyconf</groupId>
<artifactId>easyconf</artifactId>
<version>0.9.5</version>
<exclusions>
<exclusion>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
</exclusion>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
<groupId>xdoclet</groupId>
<artifactId>xdoclet</artifactId>
<artifactId>xdoclet-web-module</artifactId>
<groupId>xpp3</groupId>
<artifactId>xpp3_min</artifactId>
</exclusions>
<groupId>jalopy</groupId>
<artifactId>jalopy</artifactId>
<version>1.5rc3</version>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
<groupId>net.java.dev.rome</groupId>
<artifactId>rome</artifactId>
<version>1.0.0</version>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.2</version>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<artifactId>axis-ant</artifactId>
<artifactId>axis-jaxrpc</artifactId>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<!--edited by charles to exclude the sjf4j ,otherwise it will use the old version if slf4j-->
<!--start exclusion-->
<exclusions>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<!-- end exclusion -->
<version>2.1.2</version>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>0.8</version>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>7.0.22</version>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>1.0-alpha-9</version>
<artifactId>plexus-io</artifactId>
<version>1.0-alpha-1</version>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.16</version>
<!--edited by charles to remove the old version of slf4j-->
<!--
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.11</version>
-->
<!--edited by charles to add the new version of slf4j 1.6.4-->
<!--begin adding new dependency of slf4j-->
<version>1.6.4</version>
<!--end new dependency of slf4j-->
<!-- edited by charles to remove the old version of slf4j-log4j -->
<!--
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
<version>2.0.8</version>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependencies>
</project>
我們吧這個檔案複制并且取代~/.m2/repository中liferay-maven-plugin的pom檔案,然後再運作liferay:plugin,終于就可以順利的執行了:
...
- Refreshed the configuration of all components
- Properties for jar:file:/C:/Users/asus/.m2/repository/com/liferay/portal/portal-impl/6.1.0/portal-impl-6.1.0.jar!/portal loaded from [jar:file:/C:/Users/asus/.m2/repository/com/liferay/portal/portal-impl/6.1.0/portal-impl-6.1.0.jar!/portal.properties]
Loading jar:file:/C:/Users/asus/.m2/repository/com/liferay/portal/portal-impl/6.1.0/portal-impl-6.1.0.jar!/portal.properties
Building Foo
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\service\persistence\FooPersistenceImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\persistence\FooPersistence.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\persistence\FooUtil.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\model\impl\FooModelImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\model\impl\FooBaseImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\model\impl\FooImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\model\FooModel.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\model\Foo.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\model\impl\FooCacheModel.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\model\FooClp.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\model\FooWrapper.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\model\FooSoap.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\service\impl\FooLocalServiceImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\service\base\FooLocalServiceBaseImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooLocalService.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooLocalServiceUtil.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooLocalServiceClp.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooLocalServiceWrapper.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\service\impl\FooServiceImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\service\base\FooServiceBaseImpl.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooService.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooServiceUtil.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooServiceClp.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\FooServiceWrapper.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\src\main\java\com\charles\service\http\FooServiceSoap.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\messaging\ClpMessageListener.java
Writing D:\IT\Eclipse\Workspace\mavensb\mavensb-portlet\..\mavensb-portlet-service\src\main\java\com\charles\service\ClpSerializer.java
[INFO] BUILD SUCCESS
[INFO] Total time: 27.216s
[INFO] Finished at: Wed Jun 13 22:46:18 CST 2012
[INFO] Final Memory: 13M/31M
最終執行會在我們項目中生成預期的servicebuilder(一組檔案)
<a href="http://blog.51cto.com/attachment/201206/231007196.png" target="_blank"></a>
為了友善,我也上傳了我改動的檔案,請複制到你機器上的~\.m2\repository\com\liferay\maven\plugins\liferay-maven-plugin\6.1.0 目錄中。
我相信,我是Liferay社群對于Liferay 6.1版本的最新解決這個問題的人了,至少在Liferay論壇上,2012年6月1日之前還沒有人能解決這個問題。
本文轉自 charles_wang888 51CTO部落格,原文連結:http://blog.51cto.com/supercharles888/897825,如需轉載請自行聯系原作者