我已经构建了一个Web应用程序,其中包含一个带有mysql数据库和tomcat7服务器的Spring MVC项目。现在发布到OpenShift的GIT。 但启动服务器只需要160毫秒,我可以清楚地看到没有任何东西正在加载。
如何进行实际部署并将Openshift Tomcat连接到我的项目? 我可以编码,但部署方面我不是一个聪明的灯泡。
有什么问题?
修改 按要求pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.afterguard</groupId>
<artifactId>SailPlanner</artifactId>
<version>0.8.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>sailplanner</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.openshift</groupId>
<artifactId>openshift-java-client</artifactId>
<version>2.7.0.Final</version>
</dependency>
</dependencies>
</project>
web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>SailPlanner</display-name>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>sailplanner</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sailplanner</servlet-name>
<!-- <url-pattern>/</url-pattern> -->
<url-pattern>/index</url-pattern>
<url-pattern>/inside/admin</url-pattern>
<url-pattern>/inside/admin/save</url-pattern>
<url-pattern>/inside/admin/delete</url-pattern>
<url-pattern>/inside/calendar_race</url-pattern>
<url-pattern>/inside/calendar_cruise</url-pattern>
<url-pattern>/inside/blog</url-pattern>
<url-pattern>/inside/blog/submit</url-pattern>
<url-pattern>/inside/blog/delete</url-pattern>
<url-pattern>/inside/event_feed</url-pattern>
<url-pattern>/inside/event/create</url-pattern>
<url-pattern>/inside/event/delete</url-pattern>
<url-pattern>/inside/event/crew/add</url-pattern>
<url-pattern>/inside/event/crew/remove</url-pattern>
<url-pattern>/inside/event/save</url-pattern>
<url-pattern>/login</url-pattern>
<url-pattern>/logout</url-pattern>
<url-pattern>/403</url-pattern>
<url-pattern>/registration</url-pattern>
<url-pattern>/inside/yacht/create</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/sailplanner-servlet.xml,
/WEB-INF/spring-security.xml,
/WEB-INF/spring-database.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Git Push Log(成功构建):
Repository ssh://566ffc920c1e668c8a000049@afterguard-sailplanner.rhcloud.com/~/git/afterguard.git/
Stopping jbossews cartridge
Sending SIGTERM to jboss:333213 ...
Stopping MySQL 5.5 cartridge
Stopping PHPMyAdmin cartridge
Waiting for stop to finish
Waiting for stop to finish
Repairing links for 1 deployments
Building git ref 'master', commit 277c797
Using Maven mirror /var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo//.openshift/config/settings.rhcloud.xml
Apache Maven 3.0.4 (r1232336; 2012-12-18 14:36:37-0500)
Maven home: /usr/share/java/apache-maven-3.0.4
Java version: 1.7.0_91, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "2.6.32-573.12.1.el6.x86_64", arch: "i386", family: "unix"
Found pom.xml... attempting to build with 'mvn --global-settings /var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo//.openshift/config/settings.rhcloud.xml clean package -Popenshift -DskipTests'
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SailPlanner 0.8.0
[INFO] ------------------------------------------------------------------------
Downloading: http://maven.repository.redhat.com/techpreview/all/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.pom
...A LOT OF BUILDING AND DOWNLOADING...
Downloaded: http://mirror.ops.rhcloud.com/nexus/content/groups/public/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar (422 KB at 6105.7 KB/sec)
[INFO] Packaging webapp
[INFO] Assembling webapp [SailPlanner] in [/var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo/target/sailplanner]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo/WebContent]
[INFO] Webapp assembled in [517 msecs]
[INFO] Building war: /var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo/WebContent/ROOT.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.062s
[INFO] Finished at: Tue Dec 22 05:35:45 EST 2015
[INFO] Final Memory: 16M/161M
[INFO] ------------------------------------------------------------------------
Preparing build for deployment
Deployment id is 0f103f85
Activating deployment
Starting MySQL 5.5 cartridge
Starting PHPMyAdmin cartridge
Starting jbossews cartridge
Found 127.3.145.129:8080 listening port
-------------------------
Git Post-Receive Result: success
Activation status: success
Deployment completed with status: success
OpenShift的Tomcat日志:
Dec 22, 2015 6:47:27 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1503 ms
Dec 22, 2015 6:47:27 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 22, 2015 6:47:27 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Dec 22, 2015 6:47:27 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-127.3.145.129-8080"]
Dec 22, 2015 6:47:27 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 251 ms
ROOT.WAR的文件结构,位于/var/lib/openshift/<uuid>/app-root/runtime/repo/WebContent
:
|- META-INF
|- resources
|-- css
|-- fonts
|-- img
|-- js
|- WEB-INF
|-- classes
|--- com
|---- ...
|-- jsp
|--- index.jsp
|--- more jsp-sites
|-- jspf
|--- JSPF SITES I USE
|-- lib
|--- THE LIBS
|-- sailplanner-servlet.xml
|-- spring-datasource.xml
|-- spring-security.xml
|-- web.xml
答案 0 :(得分:4)
您似乎忘记在 pom.xml 中添加openshift maven配置文件,如下所示,并使用正确的 maven-war-plugin 配置。
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>travel</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
然后你的应用程序结构似乎不寻常。通常使用maven构建WAR,将webapp内容放在 src / main / webapp 中, src / main / resources 中的资源 src中的WAR特定类/主/ JAVA
查看 maven-war-plugin 用户指南here。
最后,检查这些文档,这些文档可以帮助您了解如何使用OpenShift将应用程序部署到Tomcat:
如果您按照这些文档中描述的正确步骤进行操作,那么任何git push都会触发构建和应用程序重新部署到Tomcat
修改强> 由于您现在有一个构建编译问题(不支持Java 8),您应该看一下这个答案:invalid target release 1.8
答案 1 :(得分:2)
您实际执行了git push
和git push
吗?
如果是,您可以从function createRowColumn(row) {
var column = document.createElement("td");
row.appendChild(column);
return column;
}
function addRow() {
var newrow = document.createElement("tr");
var numericColumn = createRowColumn(newrow);
var checkColumn = createRowColumn(newrow);
var dateColumn = createRowColumn(newrow);
var emptyColumn = createRowColumn(newrow);
var removeColumn = createRowColumn(newrow);
var checkbox = document.createElement("input");
checkbox.setAttribute("type", "checkbox");
checkColumn.appendChild(checkbox);
var datebox = document.createElement("input");
datebox.setAttribute("type", "date");
//datebox.setAttribute("id", "mydate"); //don't reuse id's
dateColumn.appendChild(datebox);
emptyColumn.setAttribute("contenteditable", "true");
var remove = document.createElement("input");
remove.setAttribute("type", "button");
remove.setAttribute("value", "Delete Row");
remove.setAttribute("onClick", "deleteRow(this)");
removeColumn.appendChild(remove);
var table = document.getElementById('t1');
var tbody = table.querySelector('tbody') || table;
var count = tbody.getElementsByTagName('tr').length;
numericColumn.innerText = count.toLocaleString() + '.';
tbody.appendChild(newrow);
}
转储日志。