標籤:appfuse full-source raw.github.com archetype illegalstateexceptio
很長一段時間沒做SSH項目了,最近抽空看了一下升級到3.x的appfuse,對新版本使用過程中出現的一些問題進行了排查,匯總如下,以備後用。本文原文出處: http://blog.csdn.net/bluishglc/article/details/38640715 嚴禁任何形式的轉載,否則將委託CSDN官方維護權益!
起步
使用appfuse的第一步自然是通過archetype:generate產生項目。這本不是一問題,官方的QuickStart:http://appfuse.org/display/APF/AppFuse+QuickStart 頁面上給出了協助我們產生archetype:generate命令列的工具,不幸的是這個頁面引用了一些位於googleapis.com上的js檔案,中國的小朋友們可能擷取不了這些檔案(原因你懂的),至少在寫作這篇文章的時候googleapis.com是無法從國內訪問的。如果缺少這些JS檔案,頁面就不能自動產生命令列了,雖然這個命令本身並不複雜,但是手寫出它的archetypeRepository地址和archetypeArtifactId還是很費力的,下面給出四個樣本,可依此為藍本進行修改:
樣本一:建立名稱為demo的基於spring mvc+spring+hibernate的單一工程,appfuse版本:3.0.0
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring-archetype -DarchetypeVersion=3.0.0 -DgroupId=com.yourcompany -DartifactId=demo -DarchetypeRepository=https://oss.sonatype.org/content/repositories/appfuse
樣本二:建立名稱為demo的基於spring mvc+spring+hibernate的單一工程,appfuse版本:3.0.1-SNAPSHOT
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring-archetype -DarchetypeVersion=3.0.1-SNAPSHOT -DgroupId=com. yourcompany -DartifactId=demo -DarchetypeRepository=https://oss.sonatype.org/content/repositories/appfuse
樣本三:建立名稱為sample的基於spring mvc+spring+hibernate的多模組工程,appfuse版本:3.0.0
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-modular-spring-archetype -DarchetypeVersion=3.0.0 -DgroupId=com. yourcompany -DartifactId=sample -DarchetypeRepository=https://oss.sonatype.org/content/repositories/appfusec
樣本四:建立名稱為sample的基於spring mvc+spring+hibernate的多模組工程,appfuse版本:3.0.1-SNAPSHOT
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-modular-spring-archetype -DarchetypeVersion=3.0.1-SNAPSHOT -DgroupId=com. yourcompany -DartifactId=sample -DarchetypeRepository=https://oss.sonatype.org/content/repositories/appfusec
產生項目之後,按照官方文檔的指導很容易就可以build並運行建立立起來的工程了,但是如果你不走運的話,就可能會遇到如下一些問題:
問題與解決方案
問題一:
使用3.0.0版本,執行mvn appfuse:full-source失敗,使用 mvn appfuse:full-source -e查看錯誤資訊,報如下錯誤:
[ERROR] Failed to execute goal org.appfuse.plugins:appfuse-maven-plugin:3.0.0:full-source (default-cli) on project demo: Execution default-cli of
goal org.appfuse.plugins:appfuse-maven-plugin:3.0.0:full-source failed: java.net.UnknownHostException: raw.github.com: Unknown host raw.github.com
解決方案:
對於該問題,appfuse的作者在http://appfuse.547863.n4.nabble.com/Appfuse-failed-to-get-full-source-td4657086.html 中給出瞭解釋,原因是github更改的子網域名稱導致的。為此作者建立了一個3.0.1-SNAPSHOT版本來解決這一問題。就我個人的使用方式來看這是一個很奇怪的問題,第一次執行mvn appfuse:full-source確實遇到了這一問題,第二天就沒有問題了,理論上raw.github.com會重新導向到新的目標網域名稱,但是看起來受到網路以及配置的種種原因,這個問題確實是有可能發生的。不過使用3.0.1-SNAPSHOT版本並非是一個好的解決方案,接下來的常見問題二就是發生在3.0.1-SNAPSHOT版本上的。
問題二:
使用3.0.1-SNAPSHOT版本,執行mvn jetty:run時報如下錯誤:
java.lang.IllegalStateException: org.slf4j.LoggerFactory could not be successfully initialized.
解決方案:
這個問題確實是開發人員給使用者挖的一個“坑”,僅僅從報錯日誌上很難找到直接原因,但是日誌中的一行資訊:
An API incompatibility was encountered while executing org.eclipse.jetty:jetty-maven-plugin:xxxxxx:run: java.lang.ExceptionInInitializerError: null
多少還是給了我們一些線索,檢查使用3.0.1-SNAPSHOT版本產生的pom.xml檔案,我們發現jetty外掛程式的配置是這樣的:
<plugin><groupId>org.eclipse.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>8.1.14.v20131031</version><configuration><webApp><contextPath>/</contextPath></webApp></configuration></plugin>
再仔細地檢查,我們就會發現jetty遷移eclipse之後,其版本是從9.0.0開始的,根本沒有8.1.14.v20131031這個版本,而這個8.1.14.v20131031版本是怎麼來的呢?看看3.0.0的pom.xml我們找到了答案:
<plugin><groupId>org.mortbay.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>8.1.14.v20131031</version><configuration><webApp><contextPath>/</contextPath></webApp></configuration></plugin>
8.X版本的jetty還是其在mortbay下時的版本。很顯然,作者在從3.0.0向3.0.1-SNAPSHOT升級的時候,配錯了jetty的版本!這樣,解決方案也就出來了,把外掛程式配置中的<groupId>org.eclipse.jetty</groupId>改為<groupId>org.mortbay.jetty</groupId>就可以了。
建議
由於3.0.1-SNAPSHOT尚處於開發階段,在不同時期使用可能會出現不同的問題,前文提及的第二個問題就是一個例子,因此建議先使用3.0.0版。