将gwt超级资源排除在最终战争之外



对于具有以下结构的GWT项目:

src
/java
...
/super
/java
/text
/DecimalFormat.java

是否可以只在project-sources.jar中包含DecimalFormat.java,而不在project.jar(包含已编译的.class文件)中?

我目前使用的POM是:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration combine.self="override">
<excludes>
<exclude>**/src/emulation/*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<includes>
<include>**/src/emulation/**/*.java</include>
</includes>
</configuration>
</plugin>

但以上所有内容都不起作用,因为路径应该是相对于src/java的sources文件夹的。同时尝试使用".."似乎也不起作用。

有没有什么插件可以更具体地处理这个问题?我看过托马斯·布罗耶的一些相关作品https://tbroyer.github.io/gwt-maven-plugin/add-super-sources-mojo.html.但我无法使它适用于这种情况。

谢谢!

我也无法使它与maven-source-plugin一起工作(由于某种原因,includesexcludes过滤器被完全忽略)。然而,在多模块配置中,这似乎是可能的。

家长

pom.xml

这是一个有点冗长的问题,因为我在本地实现了它,直到我的代码风格,但你可以完全忽略它,因为它不是什么新鲜事,只是两个子模块的父模块。

<?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/maven-v4_0_0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>gwt-advanced</artifactId>
<version>0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<modules>
<module>app</module>
<module>emulation</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>2.8.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.8.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

仿真子模块

仿真/pom.xml

这是Javajava.text包仿真类的pom。如上所述,我无法使maven-source-plugin与过滤器一起正常工作,但由于该模块是分离的,因此可以很容易地将源提供给目标源JAR文件(该文件自动具有sources分类器)。

<?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>
<parent>
<groupId>test</groupId>
<artifactId>gwt-advanced</artifactId>
<version>0-SNAPSHOT</version>
</parent>
<artifactId>gwt-advanced-emulation</artifactId>
<version>0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

仿真/src/main/java/text/text.gwt.xml

只是一个GWT模块定义,没有什么新鲜事。它可能也位于资源库中,但这更多的是一个代码定义,因此可以在这里进行测试。

<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.user.User"/>
<source path=""/>
</module>

仿真/src/main/java/text/DecimalFormat.java

仅用于测试目的的模拟类:

package java.text;
public final class DecimalFormat {
private final String pattern;
public DecimalFormat(final String pattern) {
this.pattern = pattern;
}
public String format(final double value) {
return "{pattern=" + pattern + ", value=" + value + "}";
}
}

应用程序子模块

这个pom.xml不包含GWT构建周期,它隐式地允许您自己进行构建。注意模拟模块依赖项的<classifier>sources</classifier>元素——这对GWT来说是最重要的,因为它只能编译Java源代码,而不能处理Java字节码。<scope>provided</scope>确保不将依赖项附加到目标工件(这是不必要的,因为所有JavaScript文件都是生成的,并且在服务器上预编译时不需要Java源代码)。

app/pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>test</groupId>
<artifactId>gwt-advanced</artifactId>
<version>0-SNAPSHOT</version>
</parent>
<artifactId>gwt-advanced-app</artifactId>
<version>0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-codeserver</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>gwt-advanced-emulation</artifactId>
<version>0</version>
<scope>provided</scope>
<classifier>sources</classifier>
</dependency>
</dependencies>
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<configuration>
<runTarget>index.html</runTarget>
<module>test.ApplicationEntryPoint</module>
<copyWebapp>true</copyWebapp>
</configuration>
</plugin>
</plugins>
</build>
</project>

app/src/main/webapp/WEB-INF/WEB.xml

web容器的模块描述符。

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

app/src/main/webapp/index.html

用于加载应用程序引导程序的示例GWT应用程序容器页面。它将显示"格式化"的eπ

<!DOCTYPE html>
<html>
<head>
<title>GWT Test</title>
<script type="text/javascript" language="javascript" src="test.ApplicationEntryPoint/test.ApplicationEntryPoint.nocache.js"></script>
</head>
<body>
<table>
<tbody>
<tr>
<th>e</th>
<td id="e"></td>
</tr>
<tr>
<th>pi</th>
<td id="pi"></td>
</tr>
</tbody>
</table>
</body>
</html>

app/src/main/java/test/ApplicationEntryPoint.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.resources.Resources"/>
<inherits name="com.google.gwt.user.User"/>
<inherits name="java.text.Text"/>
<entry-point class="test.ApplicationEntryPoint"/>
<source path=""/>
</module>

app/src/main/java/test/ApplicationEntryPoint.java

示例应用程序:

package test;
import java.text.DecimalFormat;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Document;
import static java.lang.Math.E;
import static java.lang.Math.PI;
public final class ApplicationEntryPoint
implements EntryPoint {
private ApplicationEntryPoint() {
}
@Override
public void onModuleLoad() {
final Document document = Document.get();
final DecimalFormat decimalFormat = new DecimalFormat("###,###.###");
document.getElementById("e").setInnerText(decimalFormat.format(E));
document.getElementById("pi").setInnerText(decimalFormat.format(PI));
}
}

输出

e  | {pattern=###,###.###, value=2.718281828459045}
pi | {pattern=###,###.###, value=3.141592653589793}

mvn

GWT构建周期的Maven命令

  • mvn clean gwt:run——启动嵌入式web容器
  • mvn clean gwt:compile install-执行GWT编译(本质上是JavaScript文件生成),打包一个war文件并将工件安装到本地存储库;工件可以很容易地部署到Tomcat

gwt-advanced-app-0.war工件列表:

Archive:  gwt-advanced-app-0.war
Length      Date    Time    Name
---------  ---------- -----   ----
0  xxxx-xx-xx xx:xx   META-INF/
143  xxxx-xx-xx xx:xx   META-INF/MANIFEST.MF
0  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/
0  xxxx-xx-xx xx:xx   WEB-INF/
0  xxxx-xx-xx xx:xx   WEB-INF/classes/
0  xxxx-xx-xx xx:xx   WEB-INF/classes/test/
0  xxxx-xx-xx xx:xx   WEB-INF/deploy/
0  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/
0  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/rpcPolicyManifest/
0  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/symbolMaps/
349  xxxx-xx-xx xx:xx   index.html
11323  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/502BBFC907647230FA696491F4CA7597.cache.js
11318  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/548A93E7618BA4A5D5DDE22181A086C0.cache.js
43  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/clear.cache.gif
317  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/compilation-mappings.txt
11320  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/E664752A6412123C29A3FFF0FEE4665A.cache.js
11323  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/E891921037077276BDFB0E285016FD1C.cache.js
11325  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/FE9CAA3D03DD64BC3E380FCDFFCA4614.cache.js
14981  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/test.ApplicationEntryPoint.devmode.js
8167  xxxx-xx-xx xx:xx   test.ApplicationEntryPoint/test.ApplicationEntryPoint.nocache.js
1017  xxxx-xx-xx xx:xx   WEB-INF/classes/test/ApplicationEntryPoint.class
89  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/rpcPolicyManifest/manifest.txt
32563  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/symbolMaps/502BBFC907647230FA696491F4CA7597.symbolMap
32544  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/symbolMaps/548A93E7618BA4A5D5DDE22181A086C0.symbolMap
32548  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/symbolMaps/E664752A6412123C29A3FFF0FEE4665A.symbolMap
32553  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/symbolMaps/E891921037077276BDFB0E285016FD1C.symbolMap
32573  xxxx-xx-xx xx:xx   WEB-INF/deploy/test.ApplicationEntryPoint/symbolMaps/FE9CAA3D03DD64BC3E380FCDFFCA4614.symbolMap
147  xxxx-xx-xx xx:xx   WEB-INF/web.xml
0  xxxx-xx-xx xx:xx   META-INF/maven/
0  xxxx-xx-xx xx:xx   META-INF/maven/test/
0  xxxx-xx-xx xx:xx   META-INF/maven/test/gwt-advanced-app/
1579  xxxx-xx-xx xx:xx   META-INF/maven/test/gwt-advanced-app/pom.xml
106  xxxx-xx-xx xx:xx   META-INF/maven/test/gwt-advanced-app/pom.properties
---------                     -------
246328                     33 files

由于目标war中的WEB-INF/classes/test/ApplicationEntryPoint.class条目,可能还有更多需要微调的内容,但没有提供依赖关系的源代码。

最新更新