2015-12-18 171 views
5

私のビルドプロセスをMavenからGradle(V 2.9)に変更しようとしています。 Mavenでは、次のようにJSPのプリコンパイルを使用していました。GradleでJSPをプリコンパイル

 <plugin> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-jspc-maven-plugin</artifactId> 
      <version>9.2.7.v20150116</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <id>jspc</id> 
        <goals> 
         <goal>jspc</goal> 
        </goals> 
        <configuration> 
         <excludes>**\/*inc_page_bottom.jsp,**\/*inc_page_top.jsp</excludes> 
         <includes>**\/*.jsp</includes> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

これはうまくいきました。 今、私はgradleで同じことをする方法を見つけようとしています。 私はいくつかの情報/ build.gradleの例を見つけましたが、実際には何も動作していませんでした。私は現在サーブレットコンテナとしてTomcat 7を使用していますが、8週間に数週間で切り替える予定です。ターゲットサーブレットコンテナ用にそれらをコンパイルするのはもちろん完璧でしょうが、まず最初にこれを実行したようにプリコンパイルすることになります桟橋と一緒に/桟橋で。

私にエラーを与える私の現在のbuild.gradleの一部:次のエラーを取得

buildscript { 
    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.4' 
    } 
} 

apply plugin: 'com.bmuschko.tomcat' 

tomcat { 
    jasper { 
     validateXml = true 
     errorOnUseBeanInvalidClassAttribute = false 
     compilerSourceVM = "1.8" 
     compilerTargetVM = "1.8" 
    } 
} 

task compileJsps(type: JavaCompile, dependsOn: 'clean') { 
    dependsOn tomcatJasper 
    group = 'build' 
    description = 'Translates and compiles JSPs' 
    classpath = configurations.tomcat + sourceSets.main.output + sourceSets.main.runtimeClasspath 
    sourceCompatibility = "1.8" 
    targetCompatibility = "1.8" 
    destinationDir = file("$buildDir/jasper-classes") 
    sourceSets { 
     main { 
      java { 
       srcDir "$buildDir/jasper" 
      } 
     } 
    } 
} 

dependencies { 
    def tomcatVersion = '7.0.59' 
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", 
     "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}", 
     "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}" 
} 

イム:Tomcatの7でこのJSPの実行

:tomcatJasper FAILED 
FAILURE: Build failed with an exception. 
* What went wrong: 
Execution failed for task ':tomcatJasper'. 
> org.apache.jasper.JasperException: file:/xxx/xxx/xxx/xxx/src/main/webapp/index.jsp (line: 6, column: 0) The value for the useBean class attribute xxx.xxx.xxx.XxxXxx is invalid. 

が正常に動作します... 誰かが最新のハウツーやヒントを持っていますか?

+0

この回答をお持ちですか? <%@ include file = "directives.jsp"%>はサーバー上で動作しますが、プリコンパイルのコンテキストでは動作しませんでした –

+0

残念ながら、何も解決しませんでした。 – StephanM

+0

私たちは、桟橋のjdt-coreの隆起を助けて、jre 18u112と互換性のあるジャスパーコンパイラを手に入れました –

答えて

1

gradleを使用すると、JSPCコンパイラを直接呼び出すことができます。そうすれば、何が起こっているのかは明白です。私たちは次のようなものを使用しています。

注意すべき事項はいくつかあります。

  1. それはクラスパス
  2. に追加する必要があるので、JSPCコンパイラは、JSPCコンパイラは、log4jのを使用していますので、我々はプロパティ
  3. 出力にいくつかの基本的なログファイルJSPCコンパイラを作成し、Antのに依存していますJettyに埋め込まれています。これは "providedCompile"依存関係で、したがってランタイムクラスパスに依存します。

とにかく、私たちのグラデルは似ています。

configurations { 
    jspc 
} 

dependencies { 
    jspc 'org.apache.ant:ant:1.10.1' 
} 

def jspSrc = "$projectDir/src/main/webapp" 
def jspJavaSrc = "$buildDir/jsp-java-source" 
def jspPackage = "com.example.jsp" 

task writeJspcProperties(type: WriteProperties) { 
    outputFile = "$buildDir/log4j.jspc.properties" 
    property('log4j.rootLogger', 'WARN, stdout') 
    property('log4j.logger.org.apache', 'INFO, stdout') 
    property('log4j.appender.stdout', 'org.apache.log4j.ConsoleAppender') 
    property('log4j.appender.stdout.Target', 'System.out') 
    property('log4j.appender.stdout.layout', 'org.apache.log4j.PatternLayout') 
    property('log4j.appender.stdout.layout.ConversionPattern', '%d [%C] %m%n') 
} 

task jspToJava(type: JavaExec, dependsOn: [compileJava, writeJspcProperties]) { 

    inputs.dir jspSrc 
    outputs.dir jspJavaSrc 

    File xmlPartial = file("$jspJavaSrc/WEB-INF/web.xml.partial") 

    doFirst { 
     // Create the target WEB-INF folder so the JspC can create the web.xml.partial 
     File webInfFolder = xmlPartial.getParentFile() 
     if (!webInfFolder.exists()) { 
      webInfFolder.mkdirs() 
     } 
    } 

    classpath = configurations.jspc + sourceSets.main.runtimeClasspath 
    main = 'org.apache.jasper.JspC' 
    jvmArgs "-Dlog4j.configuration=file:$buildDir/log4j.jspc.properties" 

    args '-webapp', jspSrc, 
      '-d', jspJavaSrc, 
      '-p', jspPackage, 
      '-webxmlencoding', 'UTF-8', 
      '-webinc', xmlPartial.absolutePath 

    doLast { 
     // Merge the partial XML with the original 
     String originalXML = file("$jspSrc/WEB-INF/web.xml").text 
     String xmlToMerge = xmlPartial.text 
     String mergedXML = originalXML.replaceFirst('(?s)(<web-app.*?>)', '$1' + xmlToMerge) 
     file("$jspJavaSrc/WEB-INF/web.xml").text = mergedXML 
    } 
} 

[編集;大幅に下にあるメインのbuild.gradleではJSPのコンパイル]

0

を簡素化

apply from: 'jspc.gradle' 

を行う次に、あなたのjspc.gradleファイルは次のようになります。プリコンパイルを使用するために、その後

buildscript { 
    repositories { 
     jcenter() 
    } 


    dependencies { 
     classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.5' 
    } 
} 

apply plugin: com.bmuschko.gradle.tomcat.TomcatPlugin 
apply plugin: 'java' 

dependencies { 
    def tomcatVersion = '8.0.42' 
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", 
      "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}", 
      "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}", 
      "javax.servlet:jstl:1.2" 

    providedCompile "javax.servlet:servlet-api:2.5" 

} 

ありません。

gradle tomcatJasper 
関連する問題