简体   繁体   English

在Tomcat 7上将Maven Java应用程序部署到OpenShift

[英]Deploying Maven Java application to OpenShift on Tomcat 7

I have a Java application built with Maven running on my local PC. 我在本地PC上运行了一个用Maven构建的Java应用程序。 I'm using Eclipse and Apache/Tomcat for my server. 我正在为服务器使用Eclipse和Apache / Tomcat。 I have two projects in my application: 我的应用程序中有两个项目:

  1. The Java code (JavaApp) Java代码(JavaApp)
  2. The Web Application (WebApp) Web应用程序(WebApp)

In my WebApp Pom I am including my JavaApp as a dependency. 在WebApp Pom中,我将JavaApp包含为依赖项。 This runs fine on my local server with Eclipse & Apache/Tomcat. 在使用Eclipse和Apache / Tomcat的本地服务器上,此命令运行良好。

I have an OpenShift account and have created an Application/Cartridge for Tomcat 7 (JBoss EWS 2.0). 我有一个OpenShift帐户,并且已经为Tomcat 7(JBoss EWS 2.0)创建了一个应用程序/盒。 Using Git I was followed the instructions and; 我使用Git遵循了说明,并且;

  1. Created a clone of the OpenShift app on my local Git. 在本地Git上创建了OpenShift应用的副本。
  2. I deleted the SRC directory and pom.xml file from the local clone. 我从本地克隆中删除了SRC目录和pom.xml文件。
  3. Using Maven I created a WAR file from my WebApp project. 使用Maven,我从WebApp项目中创建了一个WAR文件。 I verified by looking in to the WAR file that my JavaApp is included in the WEB-INF/lib as a jar file. 我通过查看WAR文件来验证,我的JavaApp作为jar文件包含在WEB-INF / lib中。
  4. I copied my WAR file in to the clone's webapps directory. 我将WAR文件复制到克隆的webapps目录中。
  5. I issued the git add . 我发布了git add。 to update my new files. 更新我的新文件。
  6. I issued the git commit -m "updated war file" command to commit the changes 我发出了git commit -m“ updated war file”命令来提交更改
  7. I issued the git push command to push my application to OpenShift. 我发出了git push命令将我的应用程序推送到OpenShift。

My cmd window reports the push is a success. 我的cmd窗口报告该推送成功。 I then go to my application URL and I'm getting jsp errors. 然后,我转到我的应用程序URL,并且遇到了jsp错误。 The way my application is configured, it goes to a servlet first before being directed to the index.jsp. 我的应用程序的配置方式是先进入servlet,然后再定向到index.jsp。 I've attached an object to the page to populate some fields. 我在页面上附加了一个对象,以填充一些字段。 The errors are saying that the JSP can't find any of the methods of my object. 这些错误表明JSP找不到我的对象的任何方法。 This application is working fine on my local server. 该应用程序在我的本地服务器上运行良好。 I suspect that for some reason the OpenShift deployment of my WebApp can't find my Java code (please see below). 我怀疑由于某种原因,我的WebApp的OpenShift部署找不到我的Java代码(请参阅下文)。

I'm at a loss as to why I'm getting this error, any help would be appreciated! 我不知道为什么会收到此错误,我们将不胜感激!

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 8 in the jsp file: /index.jsp
The method getLastLocationSearched() is undefined for the type WelcomePageBean

5: <head>
6: <%@ page import ="org.williards.core.client.beans.WelcomePageBean" %>
7: <% WelcomePageBean pageBean = (WelcomePageBean)   request.getAttribute("pageBean"); %>
8: <% if(pageBean.getLastLocationSearched() != null){ %>
9:  <script>
10:         var lastSearchLocation = <%= pageBean.getLastLocationSearched() %>;
11:     </script>

Stacktrace: 堆栈跟踪:

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    org.williards.core.servlets.WelcomeServlet.pageNavigation(WelcomeServlet.java:26)
    org.williards.core.servlets.AbstractServlet.doGet(AbstractServlet.java:49)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

my first question would be whether your war (I mean the war as deployed to OpenShift, not the source) works locally? 我的第一个问题是您的战争(我的意思是部署到OpenShift而非源头的战争)是否在本地运作? I suspect that your war does not contain all dependencies. 我怀疑您的战争并不包含所有依赖关系。 To work properly in OpenShift you need to make sure OpenShift has all the dependencies. 为了在OpenShift中正常工作,您需要确保OpenShift具有所有依赖项。 When deploying as a war you can add 3rd party jars into 部署为战争时,您可以将第3方震击器添加到

src/main/webapp/WEB-INF/lib

The other option is to deploy via source which allows you to indicate dependencies via pom. 另一种选择是通过源部署,这允许您通过pom指示依赖关系。

You can see all the details in the following OpenShift kb article: https://developers.openshift.com/en/tomcat-dependencies.html 您可以在以下OpenShift kb文章中查看所有详细信息: https : //developers.openshift.com/en/tomcat-dependencies.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM