STS MAVEN對項目進行打包是的一些warning,error的解決方案


1.

[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

提示,這說明你沒有指定編碼,只能按照平台的默認編碼進行拷貝。如果原來編碼使用的是UTF-8進行保存,而這里拷貝用GBK肯定會出現亂碼的。所以要改成自己的編碼保存的方式。

解決方法,在POM.XML文件中添加:

1 <properties>
2         <project.build.sourceEncoding>
3             UTF-8
4         </project.build.sourceEncoding>
5     </properties>

 

添加后:

Using 'UTF-8' encoding to copy filtered resources.

會出現如上的提示。

 

2.

[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored

 

解決方法:在POM.XML文件中加入:

1 <plugin>
2 <groupId>org.apache.maven.plugins</groupId>
3 <artifactId>maven-war-plugin</artifactId>
4 <version>2.1.1</version>
5 <configuration>
6 <!-- http://maven.apache.org/plugins/maven-war-plugin/ -->
7 <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
8 </configuration>
9 </plugin>

 

 3.

Failed to load class "org.slf4j.impl.StaticLoggerBinder"

Hibernate使用SLF4J API記錄日志,所以在Hibernate的lib中,不再提供Log4J的包,而大部分框架依然使用Log4J記錄日志,這樣導致了兼容性問題。

     解決辦法,兩步:
        一、在編譯路徑中添加Log4J的包,比如我一直在用的log4j-1.2.8.jar;
        二、再添加一個叫做slf4j-log4j12-1.5.11.jar的包進行轉換,注意到這里的log4j12,可能對應的是log4j 1.2版本。

SLF4J官方下載:http://www.slf4j.org/download.html
下載后解壓可找到slf4j-log4j12-XX.jar

 

4.

    The import org.springframework.jdbc cannot be resolved


出現此問題是在使用JdbcTemplate的時候。與Jdbc相關的JAR包沒有引入的原因。可以到MAVEN的中央倉庫中去搜索spring jdbc然后找到相應的依賴。添加到MAVEN工程的pom.xml文件中。依賴關系如下:

 

1         <dependency>
2             <groupId>org.springframework</groupId>
3             <artifactId>spring-jdbc</artifactId>
4             <version>3.1.2.RELEASE</version>
5         </dependency>

 

 

5.

    缺少servlet-api.jar。會提示The type javax.http.HttpServletRequest cannot be resolved。可以到MAVEN的中央倉庫中搜索servlet-api然后找到相應的依賴關系。添加到MAVEN工程的pom.xml文件中。找到的依賴關系如下:

 

1         <dependency>
2             <groupId>org.apache.tomcat</groupId>
3             <artifactId>servlet-api</artifactId>
4             <version>6.0.35</version>
5         </dependency>

 

 

6.

   如果在XML文件中出現start state definition is missing的錯誤提示。則解決方法是:將該工程重建。然后重新新建該XML文件。

 

7.

在使用Spring MVC 與 FreeMarker 結合使用時如果出現could not resolve view with name in servlet with name的錯誤。則是{Dispatcher名}-servlet.xml文件中的視圖解析器配置的問題。

如果是按如下配置的,則不會出現上述問題。


<bean id="viewResolver"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">

        <property name="viewClass"
            value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"></property>

        <property name="suffix" value=".ftl"></property>

    </bean>



    <bean id="freemarkerConfig"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/WEB-INF/flt/"></property>
        <property name="freemarkerSettings">
            <props>
                <prop key="template_update_delay">0</prop>
                <prop key="default_encoding">utf-8</prop>
                <prop key="locale">zh_CN</prop>
                <prop key="number_format">0.##########</prop>

            </props>



        </property>





    </bean>

 

但是如果在第一個bean中配置了<property name="prefix" value="/" /> 則會出現上述問題。

      如果在第一個bean中的 <property name="suffix" value=".ftl"></property>配置中,如果value的值不是.ftl則也會出現上述問題。

 

原因是:freemarker本身配置了templateLoaderPath而在viewResolver中不需要配置prefix,且路徑前綴必須配置在templateLoaderPath中。

 

 

8.

  出現not found org.springframework.web.servlet.view.InternalResourceViewResolver的錯誤提示。是因為缺少spring webmvc包所致,可以再MAVEN的中央倉庫中搜索相應包的依賴關系。依賴關系如下:

 

1         <dependency>
2             <groupId>org.springframework</groupId>
3             <artifactId>spring-webmvc</artifactId>
4             <version>3.1.2.RELEASE</version>
5         </dependency>

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM