2016-07-07 8 views
2

私は、Javaのソースをjavascriptファイル(フロントエンド)に変換するためにJSweetを使用するサブモジュールでmavenプロジェクト(java Webバックエンド)を設定しました。メインモジュールのサブモジュールのプラグインタスクを実行する

私の目標は、メインモジュールがjavascriptファイルをロードするフォルダ "src/main/java/views/script"にサブモジュールのすべてのソースを移植することです。

これは、サブモジュールのPOMは、そのことについては次のようになります。

<?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>com.domain</groupId> 
<artifactId>domain-frontend</artifactId> 
<version>1.0-SNAPSHOT</version> 

<!-- jsweet --> 
<pluginRepositories> 
    <pluginRepository> 
     <id>jsweet-plugins-release</id> 
     <name>plugins-release</name> 
     <url>http://repository.jsweet.org/artifactory/plugins-release-local</url> 
    </pluginRepository> 
    <pluginRepository> 
     <snapshots /> 
     <id>jsweet-plugins-snapshots</id> 
     <name>plugins-snapshot</name> 
     <url>http://repository.jsweet.org/artifactory/plugins-snapshot-local</url> 
    </pluginRepository> 
</pluginRepositories> 


<build> 
    <plugins> 
     <plugin> 
      <groupId>org.jsweet</groupId> 
      <artifactId>jsweet-maven-plugin</artifactId> 
      <version>1.0.0-SNAPSHOT</version> 
      <configuration> 
       <outDir>src/main/java/views/script</outDir> 
       <targetVersion>ES3</targetVersion> 
       <verbose>true</verbose> 
       <encoding>UTF-8</encoding> 
      </configuration> 
      <executions> 
       <execution> 
        <id>generate-js</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>jsweet</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

</project> 

私は、メインプロジェクトの依存関係にこのサブモジュールを追加しました:

<dependency> 
     <groupId>com.domain</groupId> 
     <artifactId>domain-frontend</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </dependency> 

は、今私はフロントエンドのJSweetプラグインのタスクをしたいですメインモジュールでプラグインとして実行して、Webサーバーが再ロードされるたびにソースをトランスペアレントにします。どうすればこれを達成できますか?

答えて

1

私は、これは次のようにして動作するようになった:

1)新しいMavenプロジェクト
2を作成します)ので、のようなモジュールとしてバックエンドとフロントエンドを追加します。フロントで

<modules> 
    <module>frontend</module> 
    <module>backend</module> 
</modules> 

バックエンド親プロジェクト登録:私はいつでも今

<parent> 
    <artifactId>domain-webapp</artifactId> 
    <groupId>com.domain.webapp</groupId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 

mvn package ninja:run -pl backend 

まず、JavaソースをJavascriptファイルにコンパイルしてバックエンドをコンパイルするフロントエンドのプラグインを呼び出します。

私のフレームワークのninja:runタスクは、ファイルが変更されるたびに自動的に再構築されるため、JSweetファイルも再変換されることが非常に重要でした。

ninja:runは、バックエンドモジュールにしか認識されていないため、-pl backendを使用する必要がありました。

希望私は誰かを助けることができます!

1

ウェブアプリケーションでサブモジュールを使用するには、フロントエンドプロジェクト/モジュールをJSweetキャンディとしてパッケージ化して、バックエンドプロジェクトのキャンディ依存として参照できます。このトピックの一部はここで部分的に説明されています: https://github.com/cincheo/jsweet/blob/v1.1.1/doc/jsweet-language-specifications.md#packaging-a-jsweet-jar-candy

私はあなたに私のために働く以下のMaven構成を教えてください。

フロントエンドプロジェクトPOM

OUTDIR src/main/resources/META-INF/resources/webjars

<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>fr.xxxx</groupId> 
    <artifactId>frontend</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <repositories> 
     <repository> 
      <id>jsweet-central</id> 
      <name>libs-release</name> 
      <url>http://repository.jsweet.org/artifactory/libs-release-local</url> 
     </repository> 
     <repository> 
      <id>jsweet-external</id> 
      <name>libs-release</name> 
      <url>http://repository.jsweet.org/artifactory/ext-release-local</url> 
     </repository> 
     <repository> 
      <snapshots /> 
      <id>jsweet-snapshots</id> 
      <name>libs-snapshot</name> 
      <url>http://repository.jsweet.org/artifactory/libs-snapshot-local</url> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>jsweet-plugins-release</id> 
      <name>plugins-release</name> 
      <url>http://repository.jsweet.org/artifactory/plugins-release-local</url> 
     </pluginRepository> 
     <pluginRepository> 
      <snapshots /> 
      <id>jsweet-plugins-snapshots</id> 
      <name>plugins-snapshot</name> 
      <url>http://repository.jsweet.org/artifactory/plugins-snapshot-local</url> 
     </pluginRepository> 
    </pluginRepositories> 

    <build> 

     <sourceDirectory>src/main/java</sourceDirectory> 
     <resources> 
      <resource> 
       <directory>src/main/resources</directory> 
       <filtering>true</filtering> 
      </resource> 
     </resources> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <fork>true</fork> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.jsweet</groupId> 
       <artifactId>jsweet-maven-plugin</artifactId> 
       <version>1.2.0-SNAPSHOT</version> 
       <configuration> 
        <bundle>true</bundle> 
        <outDir>src/main/resources/META-INF/resources/webjars/${project.name}/${project.version}</outDir> 
        <tsOut>.jsweet/ts</tsOut> 
        <targetVersion>ES5</targetVersion> 
        <verbose>true</verbose> 
        <declaration>true</declaration> 
        <dtsOut>src/main/resources/src/typings</dtsOut> 
        <encoding>UTF-8</encoding> 
       </configuration> 
       <executions> 
        <execution> 
         <id>generate-js</id> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>jsweet</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>clean</id> 
         <phase>clean</phase> 
         <goals> 
          <goal>clean</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-clean-plugin</artifactId> 
       <version>3.0.0</version> 
       <configuration> 
        <filesets> 
         <fileset> 
          <directory>src/main/resources/src/typings</directory> 
          <includes> 
           <include>**/*</include> 
          </includes> 
         </fileset> 
         <fileset> 
          <directory>src/main/resources/META-INF/resources/webjars</directory> 
          <includes> 
           <include>**/*</include> 
          </includes> 
         </fileset> 
        </filesets> 
       </configuration> 
      </plugin> 
     </plugins> 

バックエンドプロジェクトPOM

キャンディは、依存関係の中で参照し、に抽出されますのでご注意くださいsrc/main/webapp/js/candies それはNB

<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>fr.xxxx</groupId> 
    <artifactId>backend</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <name>Backend</name> 

    <repositories> 
     <repository> 
      <id>jsweet-central</id> 
      <name>libs-release</name> 
      <url>http://repository.jsweet.org/artifactory/libs-release-local</url> 
     </repository> 
     <repository> 
      <id>jsweet-external</id> 
      <name>libs-release</name> 
      <url>http://repository.jsweet.org/artifactory/ext-release-local</url> 
     </repository> 
     <repository> 
      <snapshots /> 
      <id>jsweet-snapshots</id> 
      <name>libs-snapshot</name> 
      <url>http://repository.jsweet.org/artifactory/libs-snapshot-local</url> 
     </repository> 
    </repositories> 

    <properties> 
     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <jersey.version>2.22.2</jersey.version> 
     <src.dir>src/main/java</src.dir> 
    </properties> 

    <profiles> 
     <profile> 
      <id>client</id> 
      <properties> 
       <src.dir>src/main/jsweet</src.dir> 
      </properties> 

      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.jsweet</groupId> 
         <artifactId>jsweet-maven-plugin</artifactId> 
         <version>1.2.0-SNAPSHOT</version> 
         <configuration> 
          <bundle>false</bundle> 
          <module>none</module> 
          <outDir>src/main/webapp/js/app</outDir> 
          <tsOut>.jsweet/ts</tsOut> 
          <candiesJsOut>src/main/webapp/js/candies</candiesJsOut> 
          <targetVersion>ES5</targetVersion> 
          <verbose>true</verbose> 
          <includes> 
           <include>**/client/**/*.java</include> 
          </includes> 
         </configuration> 
         <executions> 
          <execution> 
           <id>generate-js</id> 
           <phase>generate-sources</phase> 
           <goals> 
            <goal>jsweet</goal> 
           </goals> 
          </execution> 
          <execution> 
           <id>clean</id> 
           <phase>clean</phase> 
           <goals> 
            <goal>clean</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 

        <plugin> 
         <artifactId>maven-clean-plugin</artifactId> 
         <version>3.0.0</version> 
         <configuration> 
          <filesets> 
           <fileset> 
            <directory>src/main/webapp/js/candies</directory> 
            <includes> 
             <include>**/*</include> 
            </includes> 
           </fileset> 
          </filesets> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
    </profiles> 

    <dependencies> 
[...] 
     <dependency> 
      <groupId>fr.xxxx</groupId> 
      <artifactId>frontend</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
      <scope>compile</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.jsweet</groupId> 
      <artifactId>jsweet-transpiler</artifactId> 
      <version>1.2.0-SNAPSHOT</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jsweet.candies</groupId> 
      <artifactId>jsweet-core</artifactId> 
      <version>1.2.0-SNAPSHOT</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <finalName>backend</finalName> 
     <sourceDirectory>${src.dir}</sourceDirectory> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1.1</version> 
      <configuration> 
      <failOnMissingWebXml>false</failOnMissingWebXml> 
      <packagingExcludes>WEB-INF/web.xml</packagingExcludes> 
      <packagingExcludes>**/fr/xxx/client/*</packagingExcludes> 
      <warName>backend</warName> 
      </configuration> 
     </plugin> 
     </plugins> 
    </build> 
</project> 

あなたのためにあなたがプロファイルを削除することができ、私はそれが駄目だと思う、あなたのバックエンドが mvn clean generate-sources -P client を使用して再デプロイするために、あなたのお菓子を構築する必要があり、まだマニュアルです:あなたの場合、フロントエンドをあなたのWebプロジェクトに直接置くほうがいいでしょう.pomにはsrc/main/javaとsrc/main/jsweetの2つのソースディレクトリがあります。君は。それは私にとって意味があります、フロントエンドのJSweetソースはwebappにあるJavascriptリソースに似ています:)

関連する問題