我有一个maven项目(java后端),它有一个子模块,该子模块使用JSweet将我的java源转换为javascript文件(前端)。
我的目标是将子模块的所有源转到文件夹“src/ main /java/view/script”中,主模块从该文件夹加载javascript文件。
这就是子模块的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插件任务在主模块中作为插件运行,以便在重新加载now服务器时传输源。我怎样才能做到这一点?
发布于 2016-07-08 12:04:04
我做了以下几件事情来解决这个问题:
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。
希望我能帮上忙!
发布于 2016-07-09 09:03:22
为了在use应用程序中使用您的子模块,您可以将前端项目/模块打包为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的,它仍然是手动的,你必须构建你的糖果,然后你的后端用mvn clean generate-sources -P client重新部署,你可以删除配置文件,我认为它对你没有用。
<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>注释:在您的情况下,最好将前端直接放在您的web项目中,注意在我们的pom中有两个源目录: src/main/java和src/main/jsweet,它可能是您的解决方案。对我来说,前端JSweet资源与中的Javascript资源相似,它们驻留在webapp:)
https://stackoverflow.com/questions/38252021
复制相似问题