昨天用spring做了個定時器,用於定時掃描某通訊公司外網ftp伺服器的約定路徑下是否有我需要的檔案並下載到本公司伺服器上。記得以前做過類似的一個定時器,覺得手到擒來的事情,沒想到又折騰了大半天,就是因為spring中commons-attributes-compiler.jar的使用問題。
問題是這樣的:掃面和下載程式,觸發類和函式,web.xml和spring配置檔案,這些準備工作都已經完成,就是在伺服器啟動的時候報錯:
INFO: Deploying web application archive GRCC.war
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC][commons-attributes-api.jar]: Required extension “ant” not found.
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC][commons-attributes-compiler.jar]: Required extension “ant” not found.
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC][commons-attributes-compiler.jar]: Required extension “javadoc” not found.
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC]: Failure to find 3 required extension(s).
Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/GRCC startup failed due to previous errors
Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/GRCC] has not been started
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC][commons-attributes-api.jar]: Required extension “ant” not found.
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC][commons-attributes-compiler.jar]: Required extension “ant” not found.
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC][commons-attributes-compiler.jar]: Required extension “javadoc” not found.
Sep 14, 2007 13:22:18 AM org.apache.catalina.util.ExtensionValidator validateManifestResources
INFO: ExtensionValidator[/GRCC]: Failure to find 3 required extension(s).
Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/GRCC startup failed due to previous errors
Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/GRCC] has not been started
並導致本專案無法啟動!
從錯誤可以看出,commons-attributes-compiler.jar需要的”ant”,”javadoc”,”qdox”無法找到,我又檢查了數遍,ant和qdox這些jar包我都已經加lib裡了,可spring就是視而不見!我鬱悶了好久,最後實在不行了,我決定解壓commons-attributes-compiler.jar,看看它的廬山真面目,裡面還真不復雜:META-INFMANIFEST.MF,compileorgapachecommonsattributesanttasks.properties,LICENSE.txt,,
NOTICE.txt,後兩個肯定是說明性的檔案,我沒有理會;第二個是屬性檔案,我看格式和註釋都沒有什麼不妥;就MANIFEST.MF裡面內容較多,並且有異常之處(我標出了):
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.3
Created-By: Apache Maven
Built-By: hen
Package: org.apache.commons.attributes.compiler
Build-Jdk: 1.4.2_05
Extension-Name: commons-attributes-compiler
Specification-Title: Attribute Compiler
Specification-Vendor: The Apache Software Foundation
Implementation-Title: org.apache.commons.attributes.compiler
Implementation-Vendor: The Apache Software Foundation
Implementation-Version: 2.2
Extension-List: ant qdox commons-attributes-api javadoc
ant-Extension-Name: ant
ant-Implementation-Version: 1.5
ant-Implementation-URL: http://www.ibiblio.org/maven/ant/jars/ant-1.
5.jar
qdox-Extension-Name: qdox
qdox-Implementation-Version: 1.5
qdox-Implementation-URL: http://www.ibiblio.org/maven/qdox/jars/qdox-1.
5.jar
commons-attributes-api-Extension-Name: commons-attributes-api
commons-attributes-api-Implementation-Version: 2.2
commons-attributes-api-Implementation-URL: http://www.ibiblio.org/maven/commons-attributes/jars/commons-attributes-api-2.2
.jar
javadoc-Extension-Name: javadoc
javadoc-Implementation-Version: 1.4
javadoc-Implementation-URL: http://www.ibiblio.org/maven/javadoc/jars/javadoc-1.4
.jar
Implementation-Vendor-Id: org.apache
X-Compile-Source-JDK: 1.4
X-Compile-Target-JDK: 1.4
這裡的URL後面的值被換行符隔開了,顯然,如果讓我們自己,是不會這麼幹的。於是,做修改如下:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.3
Created-By: Apache Maven
Built-By: hen
Package: org.apache.commons.attributes.compiler
Build-Jdk: 1.4.2_05
Extension-Name: commons-attributes-compiler
Specification-Title: Attribute Compiler
Specification-Vendor: The Apache Software Foundation
Implementation-Title: org.apache.commons.attributes.compiler
Implementation-Vendor: The Apache Software Foundation
Implementation-Version: 2.2
Extension-List: ant qdox commons-attributes-api javadoc
ant-Extension-Name: ant
ant-Implementation-Version: 1.5
ant-Implementation-URL: http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar
qdox-Extension-Name: qdox
qdox-Implementation-Version: 1.5
qdox-Implementation-URL: http://www.ibiblio.org/maven/qdox/jars/qdox-1.5.jar
commons-attributes-api-Extension-Name: commons-attributes-api
commons-attributes-api-Implementation-Version: 2.2
commons-attributes-api-Implementation-URL: http://www.ibiblio.org/maven/commons-attributes/jars/commons-attributes-api-2.2.jar
javadoc-Extension-Name: javadoc
javadoc-Implementation-Version: 1.4
javadoc-Implementation-URL: http://www.ibiblio.org/maven/javadoc/jars/javadoc-1.4.jar
Implementation-Vendor-Id: org.apache
X-Compile-Source-JDK: 1.4
X-Compile-Target-JDK: 1.4
重新打成jar包,新增到專案lib中,啟動執行,一切OK!
可是,以前寫定時器也沒遇到這種情況啊,我想這跟spring的版本有關係吧;今天用的spring2.0,可是誰把MANIFEST.MF中的URL弄錯的呢?我想不應該是官方的bug吧,可能是我不是在官網上下的spring開發包,有機會看看官網上是否也是這個樣子。不管怎麼說,專案還是在波瀾不驚中順利進行。。。