2016-05-14 14 views
0

実行可能なWARなどのCAS Webアプリケーションを実行しようとしましたが、最初に2つの解決策が見つかりました。しかし、これにはもっと良い解決策がありますか?WebサーバーをCAS webappに組み込む方法

1)メインクラスを作成してJetty組み込みサーバーを起動し、CAS warファイルを実行します。私は目標桟橋を実行することができますMavenを使って

import java.io.File; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.List; 

import org.apache.tomcat.InstanceManager; 
import org.apache.tomcat.SimpleInstanceManager; 
import org.eclipse.jetty.annotations.ServletContainerInitializersStarter; 
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer; 
import org.eclipse.jetty.plus.annotation.ContainerInitializer; 
import org.eclipse.jetty.server.Server; 
import org.eclipse.jetty.webapp.WebAppContext; 
import org.h2.jdbcx.JdbcDataSource; 

public class CasServerEmbedded { 

    public static void main(String[] args) throws Exception { 

     // Create the server 
     Server server = new Server(8080); 

     // Enable parsing of jndi-related parts of web.xml and jetty-env.xml 
     org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList 
       .setServerDefault(server); 
     classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", 
       "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration"); 

     // Create a WebApp 
     final WebAppContext webAppContext = new WebAppContext(); 
     webAppContext.setAttribute("javax.servlet.context.tempdir", getScratchDir()); 
     webAppContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", 
       ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$"); 
     webAppContext.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers()); 
     webAppContext.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager()); 
     webAppContext.addBean(new ServletContainerInitializersStarter(webAppContext), true); 
     webAppContext.setWar("C:\\temp\\cas-server-webapp-4.2.1.war"); 
     server.setHandler(webAppContext); 

     final JdbcDataSource jdbcDataSource = new JdbcDataSource(); 
     jdbcDataSource.setURL("jdbc:h2:c:\\temp\\teste;mv_store=false"); 
     jdbcDataSource.setUser("sa"); 
     jdbcDataSource.setPassword("sa"); 
     jdbcDataSource.getConnection(); 

     new org.eclipse.jetty.plus.jndi.Resource(webAppContext, "jdbc/mydatasource", jdbcDataSource); 

     server.start(); 
     server.join(); 
    } 

    /** 
    * Establish Scratch directory for the servlet context (used by JSP 
    * compilation) 
    */ 
    private static File getScratchDir() throws IOException { 
     File tempDir = new File(System.getProperty("java.io.tmpdir")); 
     File scratchDir = new File(tempDir.toString(), "embedded-jetty-jsp"); 

     if (!scratchDir.exists()) { 
      if (!scratchDir.mkdirs()) { 
       throw new IOException("Unable to create scratch directory: " + scratchDir); 
      } 
     } 
     return scratchDir; 
    } 

    /** 
    * Ensure the jsp engine is initialized correctly 
    */ 
    private static List<ContainerInitializer> jspInitializers() { 
     JettyJasperInitializer sci = new JettyJasperInitializer(); 
     ContainerInitializer initializer = new ContainerInitializer(sci, null); 
     List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>(); 
     initializers.add(initializer); 
     return initializers; 
    } 
} 

2):桟橋埋め込みサーバ内部のWARオーバーレイを開始する、実行戦争。

<?xml version="1.0" encoding="UTF-8"?> 
<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>org.jasig.cas</groupId> 
    <artifactId>cas-overlay</artifactId> 
    <packaging>war</packaging> 
    <version>1.0</version> 
    <properties> 
     <cas.version>4.2.1</cas.version> 
     <maven-jetty-plugin.version>9.3.6.v20151106</maven-jetty-plugin.version> 
     <maven.compiler.source>1.7</maven.compiler.source> 
     <maven.compiler.target>1.7</maven.compiler.target> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.jasig.cas</groupId> 
      <artifactId>cas-server-webapp</artifactId> 
      <version>${cas.version}</version> 
      <type>war</type> 
      <scope>runtime</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <warName>cas</warName> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
        <overlays> 
         <overlay> 
          <groupId>org.jasig.cas</groupId> 
          <artifactId>cas-server-webapp</artifactId> 
         </overlay> 
        </overlays> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.eclipse.jetty</groupId> 
       <artifactId>jetty-maven-plugin</artifactId> 
       <version>${maven-jetty-plugin.version}</version> 
       <configuration> 
        <jettyXml>${basedir}/etc/jetty/jetty.xml</jettyXml> 
        <systemProperties> 
         <systemProperty> 
          <name>org.eclipse.jetty.annotations.maxWait</name> 
          <value>240</value> 
         </systemProperty> 
        </systemProperties> 
        <webApp> 
         <contextPath>/cas</contextPath> 
         <overrideDescriptor>${basedir}/etc/jetty/web.xml</overrideDescriptor> 
        </webApp> 
        <webAppConfig> 
         <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames> 
        </webAppConfig> 
        <jvmArgs>-Dlog4j.configurationFile=/etc/cas/log4j2.xml -Xdebug 
         -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n</jvmArgs> 
       </configuration> 
      </plugin> 
     </plugins> 
     <finalName>cas</finalName> 
    </build> 
</project> 

あなたが見ることができるように、両方のソリューションは、スタンドアロンのWebサーバーにCASを起動しますが、私が到達しようとしていることはジェンキンスさんが何をするか何か、単純なコマンドラインで起動することができWARファイルです:javaの - jar CAS.war

Jettyを実行しているWARファイルにMavenビルドを書き出す方法はありますか?

Tks、

答えて

2

この動作は、CAS v5およびSpring Bootによって自動的に提供されます。車輪を再発明しないでください。

+0

ただし、このCAS 5バージョンはどこで入手できますか?これまでのところMavenではバージョン4.2.1しか利用できません。それについてのロードマップはありますか? https://github.com/apereo/cas と、この: –

+0

はこのあり https://github.com/apereo/cas/issues(マイルストーンによってフィルター) と、この: ます。https:// github.com/apereo/cas/milestones とこれは: https://github.com/apereo/cas-overlay-template/tree/5.0 v5はまだ開発中です。粗さを期待する。 –

+0

CAS v5がSpring Bootで動作すると言われている箇所が見つかりませんでした。どこを見ましたか? –

関連する問題