如何在 Liferay 5.2.3 中使用 guava-18.0.jar

How to use guava-18.0.jar in Liferay 5.2.3

我正在 Liferay 5.2.3 中开发我的第一个 portlet,我对这个领域还很陌生。 今天我想使用“guava-18.0.jar”来受益于“Lists.revers()”方法,我将 jar 文件放在我的 portlet 的 lib 文件夹中。它给了我这个错误:

15:55:49,905 ERROR [[fozhan]:711] Servlet.service() for servlet fozhan threw exception
java.lang.UnsupportedClassVersionError: Bad version number in .class file
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1876)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:889)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1353)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at com.sample.jsp.portlet.JSPPortlet.processAction(JSPPortlet.java:95)
        at com.sun.portal.portletcontainer.appengine.filter.FilterChainImpl.doFilter(FilterChainImpl.java:98)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:57)
        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:100)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
        at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:618)
        at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:664)
        at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:359)
        at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:604)
        at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:428)
        at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:195)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:157)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
        at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:608)
        at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:846)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
        at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:143)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:142)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:94)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:140)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:282)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:94)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.cache.CacheFilter.processFilter(CacheFilter.java:425)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:257)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.sso.opensso.OpenSSOFilter.processFilter(OpenSSOFilter.java:73)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:193)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:191)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.threadlocalcache.ThreadLocalCacheFilter.processFilter(ThreadLocalCacheFilter.java:55)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:94)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
        at java.lang.Thread.run(Thread.java:595)
15:55:49,986 ERROR [jsp:165] java.lang.UnsupportedClassVersionError: Bad version number in .class file
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1876)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:889)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1353)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at com.sample.jsp.portlet.JSPPortlet.processAction(JSPPortlet.java:95)
        at com.sun.portal.portletcontainer.appengine.filter.FilterChainImpl.doFilter(FilterChainImpl.java:98)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:57)
        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:100)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
        at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:618)
        at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:664)
        at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:359)

可能是你的Liferay版本问题。 Guava Release 10.0 于 2011 年 9 月 28 日发布,这可能是在 liferay 5.2.3

之后

你绝对可以使用这个:

Collections.reverse(list.clone());