对于具有以下结构的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。 还试图了解&#34; ..&#34;似乎不起作用。
是否有任何插件可以更具体地处理这个问题?我已经看过Thomas Broyer https://tbroyer.github.io/gwt-maven-plugin/add-super-sources-mojo.html的一些相关工作。但我无法使其适用于这种情况。
谢谢!
答案 0 :(得分:1)
我无法使用maven-source-plugin
(includes
和excludes
过滤器由于某种原因完全被忽略)。但是,在多模块配置中似乎是可能的。
这是一个有点冗长,因为我在本地实现了我的代码风格,但你可以肯定完全忽略它,因为它不是什么新东西,只是两个子模块的父代。
<?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>
这是Java java.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>
只是一个GWT模块定义,没什么新东西。它也可能位于资源库中,但这更像是一个代码定义,所以可以在这里进行测试。
<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.user.User"/>
<source path=""/>
</module>
仅用于测试目的的模拟类:
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源代码。)
http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT;
<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>
Web容器的模块描述符。
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
用于加载应用程序引导程序的示例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>
<?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>
示例应用程序:
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
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
自从目标WEB-INF/classes/test/ApplicationEntryPoint.class
中的war
条目以来,可能还有更多要微调的内容,但未提供依赖项的源代码。