2016-03-22 96 views
1

我在使用this教程在Openshift應用程序上安裝Geoserver。問題是Geoserver(.war)運行時,我必須從應用程序中刪除src文件夾和pom.xml,但我也需要在那裏開發一個應用程序。如何在Openshift上部署戰爭和應用程序

那麼,如何在WAR運行的同時保留pom.xml和src文件夾(我真的需要刪除這些東西才能使戰爭正常運行)?它甚至有可能嗎?

隨着src文件夾並pom.xml中我收到Openshift這樣的響應:

remote: [INFO] ---------- -------------------------------------------------------------- 
remote: [INFO] Building test 1.0 
remote: [INFO] ------------------------------------------------------------------------ 
remote: [INFO] 
remote: [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ test --- 
remote: [INFO] 
remote: [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ test --- 
remote: [debug] execute contextualize 
remote: [INFO] Using 'UTF-8' encoding to copy filtered resources. 
remote: [INFO] Copying 1 resource 
remote: [INFO] 
remote: [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ test --- 
remote: [INFO] Nothing to compile - all classes are up to date 
remote: [INFO] 
remote: [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ test --- 
remote: [debug] execute contextualize 
remote: [INFO] Using 'UTF-8' encoding to copy filtered resources. 
remote: [INFO] skip non existing resourceDirectory /var/lib/openshift/56f18c457628e1639500003d/app-root/runtime/repo/src/test/resources 
remote: [INFO] 
remote: [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ test --- 
remote: [INFO] No sources to compile 
remote: [INFO] 
remote: [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ test --- 
remote: [INFO] Tests are skipped. 
remote: [INFO] 
remote: [INFO] --- maven-war-plugin:2.1.1:war (default-war) @ test --- 
remote: [INFO] Packaging webapp 
remote: [INFO] Assembling webapp [test] in [/var/lib/openshift/56f18c457628e1639500003d/app-root/runtime/repo/target/test] 
remote: [INFO] Processing war project 
remote: [INFO] Copying webapp resources [/var/lib/openshift/56f18c457628e1639500003d/app-root/runtime/repo/src/main/webapp] 
remote: [INFO] Webapp assembled in [93 msecs] 
remote: [INFO] Building war: /var/lib/openshift/56f18c457628e1639500003d/app-root/runtime/repo/webapps/ROOT.war 
remote: [INFO] WEB-INF/web.xml already added, skipping 
remote: [INFO] ------------------------------------------------------------------------ 
remote: [INFO] BUILD SUCCESS 
remote: [INFO] ------------------------------------------------------------------------ 
remote: [INFO] Total time: 4.278s 
remote: [INFO] Finished at: Tue Mar 22 14:31:40 EDT 2016 
remote: [INFO] Final Memory: 8M/111M 
remote: [INFO] ------------------------------------------------------------------------ 
remote: Preparing build for deployment 
remote: Deployment id is a3cec3f4 
remote: Activating deployment 
remote: Starting Postgres cartridge 
remote: Postgres started 
remote: Emptying tmp dir: /var/lib/openshift/56f18c457628e1639500003d/jbossews//tmp/Geotools 
remote: Starting jbossews cartridge 
remote: Found 127.3.185.129:8080 listening port 
remote: ------------------------- 
remote: Git Post-Receive Result: success 
remote: Activation status: success 
remote: Deployment completed with status: success 

我的pom.xml的是默認的pom.xml是Openshift用品:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>test</groupId> 
    <artifactId>test</artifactId> 
    <packaging>war</packaging> 
    <version>1.0</version> 
    <name>test</name> 
    <repositories> 
     <repository> 
      <id>eap</id> 
      <url>http://maven.repository.redhat.com/techpreview/all</url> 
      <releases> 
       <enabled>true</enabled> 
      </releases> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>eap</id> 
      <url>http://maven.repository.redhat.com/techpreview/all</url> 
      <releases> 
       <enabled>true</enabled> 
      </releases> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </pluginRepository> 
    </pluginRepositories> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <maven.compiler.source>1.6</maven.compiler.source> 
     <maven.compiler.target>1.6</maven.compiler.target> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.postgresql</groupId> 
      <artifactId>postgresql</artifactId> 
      <version>9.2-1003-jdbc4</version> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.25</version> 
     </dependency>  
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>javax.servlet-api</artifactId> 
      <version>3.0.1</version> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 
    <profiles> 
     <profile> 
      <!-- When built in OpenShift the 'openshift' profile will be used when 
       invoking mvn. --> 
      <!-- Use this profile for any OpenShift specific customization your app 
       will need. --> 
      <!-- By default that is to put the resulting archive into the 'webapps' 
       folder. --> 
      <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --> 
      <id>openshift</id> 
      <build> 
       <finalName>test</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> 
</project> 

POSDATA:我知道如何讓戰爭在自己的背景下運行(例如http://test-testdomain.rhcloud.com/war/)。

更新:這裏是我的rhc tail -a geoserver

==> app-root/logs/postgresql.log <== 
2016-03-23 12:51:43 GMT LOG: shutting down 
2016-03-23 12:51:43 GMT LOG: database system is shut down 
2016-03-23 12:52:01 GMT LOG: could not bind socket for statistics collector: Permission denied 
2016-03-23 12:52:01 GMT LOG: trying another address for the statistics collector 
2016-03-23 12:52:01 GMT LOG: could not bind socket for statistics collector: Cannot assign requested address 
2016-03-23 12:52:01 GMT LOG: disabling statistics collector for lack of working socket 
2016-03-23 12:52:01 GMT WARNING: autovacuum not started because of misconfiguration 
2016-03-23 12:52:01 GMT HINT: Enable the "track_counts" option. 
2016-03-23 12:52:01 GMT LOG: database system was shut down at 2016-03-23 12:51:43 GMT 
2016-03-23 12:52:01 GMT LOG: database system is ready to accept connections 

==> app-root/logs/jbossews.log <== 
Mar 23, 2016 8:52:49 AM org.geoserver.GeoserverInitStartupListener contextDestroyed 
INFO: Cleaned up javabean caches 
Mar 23, 2016 8:52:50 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 
SEVERE: The web application [/geoserver] registered the JDBC driver [org.hsqldb.jdbc.JDBCDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
Mar 23, 2016 8:52:50 AM org.apache.catalina.startup.HostConfig deployWAR 
INFO: Deployment of web application archive /var/lib/openshift/56f28b760c1e66c08b000209/app-root/runtime/dependencies/jbossews/webapps/geoserver.war has finished in 40,390 ms 
Mar 23, 2016 8:52:50 AM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-127.3.223.1-8080"] 
Mar 23, 2016 8:52:50 AM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 44333 ms 

而且,我已經檢查了$ {} OPENSHIFT_JBOSSEWS_DIR web應用,和我有geoserver.warROOT.war

更新2:觸摸命令,我再次rhc til -a geoserver後得到:

==> app-root/logs/postgresql.log <== 
2016-03-23 14:46:22 GMT LOG: shutting down 
2016-03-23 14:46:22 GMT LOG: database system is shut down 
2016-03-23 14:46:40 GMT LOG: could not bind socket for statistics collector: Permission denied 
2016-03-23 14:46:40 GMT LOG: trying another address for the statistics collector 
2016-03-23 14:46:40 GMT LOG: could not bind socket for statistics collector: Cannot assign requested address 
2016-03-23 14:46:40 GMT LOG: disabling statistics collector for lack of working socket 
2016-03-23 14:46:40 GMT WARNING: autovacuum not started because of misconfiguration 
2016-03-23 14:46:40 GMT HINT: Enable the "track_counts" option. 
2016-03-23 14:46:40 GMT LOG: database system was shut down at 2016-03-23 14:46:22 GMT 
2016-03-23 14:46:40 GMT LOG: database system is ready to accept connections 

==> app-root/logs/jbossews.log <== 
Mar 23, 2016 10:47:54 AM org.geoserver.GeoserverInitStartupListener contextDestroyed 
INFO: Cleaned up javabean caches 
Mar 23, 2016 10:47:57 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 
SEVERE: The web application [/geoserver] registered the JDBC driver [org.hsqldb.jdbc.JDBCDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
Mar 23, 2016 10:47:57 AM org.apache.catalina.startup.HostConfig deployWAR 
INFO: Deployment of web application archive /var/lib/openshift/56f28b760c1e66c08b000209/app-root/runtime/dependencies/jbossews/webapps/geoserver.war has finished in 68,308 ms 
Mar 23, 2016 10:47:57 AM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-127.3.223.1-8080"] 
Mar 23, 2016 10:47:57 AM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 72395 ms 

回答

0

Openshift應用包括一個Git倉庫存儲源代碼創建的每一個應用程序中的文件夾,你推後到存儲庫中,如果您將ssh插入到您的應用程序中,則存儲庫位於$OPENSHIFT_REPO_DIR

每次您將應用程序推送到存儲庫時,都會運行一系列腳本,命名爲action hooks(使用Openshift術語)。包含的動作掛鉤會根據您選擇的墨盒而有所不同。

推入java應用程序服務器盒式磁帶後發生的事情之一是觸發maven構建,並使用$OPENSHIFT_REPO_DIR(src文件夾和pom.xml)中的內容創建WAR工件,其中也會自動部署在選定墨盒中包含的應用程序服務器上。

這基本上意味着您只需將源代碼推送到回購站,而且Openshift將處理所有事情。你不必擔心刪除任何東西。實際上,如果刪除存儲庫目錄的內容,則沒有任何東西可以構建工件。

如果您選擇了自己動手製作(DIY)墨盒,您將負責管理所有內容,並且不包含任何腳本或動作掛鉤。


更新:這可能有兩個在同一個齒輪,但需要一些調整。

首先,你的應用程序,重要的是你的pom。XML,保持<profile>部分,至少openshift輪廓,因爲它是,因爲在推送事件時,會觸發一個Maven構建與openshift輪廓,這將產生你的應用程序的WAR神器,並生成一個名爲ROOT.war文件webapps目錄。該文件將從存儲庫複製到tomcat部署目錄。

現在關於GeoServer的,從導向倉庫,它給你的文件ROOT.war爲GeoServer的應用:

  1. 你需要將其重命名爲別的,因爲觸發Maven構建將產生應用程序的ROOT.war文件,除非您修改maven-war-plugin的配置。

  2. 您需要在更名爲war文件複製到Tomcat的部署目錄。爲了做到這一點,你需要使用一個動作鉤。在這種情況下,deploy階段似乎是合適的。

您需要創建在.openshift/action_hooks目錄,命名爲deploy文件,並給它執行權限(chmod +x),並將其納入版本控制,因此它會得到您的應用程序一起推到了齒輪。該文件必須包含與複製的GeoServer WAR文件部署目錄指令的腳本,假設你改名爲戰爭geoserver.war,並駐留在webapps目錄,這個腳本會做什麼:

#!/bin/bash 

echo "Deploying Geoserver application..." 
cp ${OPENSHIFT_REPO_DIR}webapps/geoserver.war ${OPENSHIFT_JBOSSEWS_DIR}/webapps/ 

更新:我嘗試重現問題,遵循指南和應用我剛纔提到的使用tweeks,彈簧啓動應用程序作爲使用根上下文的應用程序和Geoserver,但我沒有找到任何問題。

我已經遵循的步驟是:

  1. 創建從指南中指定的存儲庫中的應用程序Openshift(tomcat7 + postgresql9.2墨盒)
  2. 克隆回購
  3. 重命名webapps/ROOT.warwebapps/geoserver.war
  4. 創建pom.xml文件(見下文源)
  5. 包括我的應用程序的src文件夾中(只是一個春天的源代碼啓動應用程序使用的/切入點打招呼世界RestController。
  6. 如上所述添加deploy動作鉤
  7. 推送代碼。

的pom.xml

<modelVersion>4.0.0</modelVersion> 

    <groupId>es.saljuama</groupId> 
    <artifactId>geoserver</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <name>geoserver</name> 
    <description>Geoserver demo project</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.3.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <java.version>1.7</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <profiles> 
     <profile> 
      <!-- Using this profile for my local machine, just the app using and embedded tomcat, with devtools, since i'm not sure if you want to make your app interact with the geoserver or not. --> 
      <id>local</id> 
      <dependencies> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-devtools</artifactId> 
        <optional>true</optional> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-web</artifactId> 
       </dependency> 
      </dependencies> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-maven-plugin</artifactId> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
     <profile> 
      <id>openshift</id> 
      <dependencies> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-web</artifactId> 
        <exclusions> 
         <exclusion> 
          <groupId>org.springframework.boot</groupId> 
          <artifactId>spring-boot-starter-tomcat</artifactId> 
         </exclusion> 
        </exclusions> 
       </dependency> 
       <dependency> 
        <groupId>javax.servlet</groupId> 
        <artifactId>javax.servlet-api</artifactId> 
        <version>3.0.1</version> 
        <scope>provided</scope> 
       </dependency> 
      </dependencies> 
      <build> 
       <finalName>geoserver</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> 

</project> 
+0

但我不能得到利用Geoserver(WAR)時運行,如果我有src文件夾和pom.xml中。 –

+0

@LadyPeanut噢,對不起,我沒有注意到的是,指南中的庫只是提供了WAR神器和一些示例數據,我認爲這是源代碼。那麼你的意圖究竟是什麼?在同一個設備上部署geoserver和你的應用程序?或只是geoserver? – saljuama

+0

我想在同一個齒輪上使用geoserver和我自己的應用程序(來自源代碼) –