12

我想配置 Spring Boot Embedded Servlet Container + GWT。我想要的方式是创建一个仅包含已编译的 gwt 文件和静态资源的 jar/war 文件。我想从 lib/* 加载 jars 并从类路径加载配置文件。

我找不到任何工作示例。实际上有一个,https://github.com/Ekito/spring-boot-gwt,但是所有的依赖和配置仍然在战争中。

有人可以提出解决方案吗?

4

2 回答 2

8

经过长时间的搜索和测试,这是我想出的解决方案:

```

<!-- POM -->
<modelVersion>4.0.0</modelVersion>
<groupId>fr.ekito.gwt</groupId>
<artifactId>gwt-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Ekito Spring Boot GWT WebApp</name>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <start-class>fr.ekito.gwt.server.ServerApplication</start-class>
    <java.version>1.7</java.version>

    <gwtVersion>2.6.0</gwtVersion>
    <googleGin>2.1.2</googleGin>
    <outputFolder>${project.build.directory}/${artifactId}</outputFolder>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
        <exclusions>
            <exclusion>
                <groupId>io.undertow</groupId>
                <artifactId>undertow-websockets-jsr</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>${gwtVersion}</version>
    </dependency>
    <dependency>
        <groupId>com.google.gwt.inject</groupId>
        <artifactId>gin</artifactId>
        <version>${googleGin}</version>
    </dependency>
</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>${start-class}</mainClass>
                <layout>ZIP</layout>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>${gwtVersion}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <runTarget>GwtWebApp.html</runTarget>
                <persistentunitcachedir>${project.build.directory}</persistentunitcachedir>
                <deploy>${project.build.directory}/gwt-deploy</deploy>
                <webappDirectory>${project.build.directory}/classes/public</webappDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

```

我的项目结构与原始项目相同,https://github.com/Ekito/spring-boot-gwt,除了一些小的变化:

  • 我有src/main/resources/public文件夹,而不是webapp文件夹,并且那里有 html 和 css 文件。
  • 不需要 web.xml 文件,spring-boot 会处理它。
  • 不需要 WEB-INF 文件夹。

结果,我有一个可运行的 jar,但由 org.springframework.boot.loader.PropertiesLauncher 运行。单个 jar 按预期工作,Tomcat 不按此处所述工作:http: //docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features -jsp 限制

另外,我可以将 lib 文件夹移到 jar 文件之外,但是为了设置loader.path属性,我需要将它放到 jar 文件中的 application.properties 中。我应该可以使用 -Dloader.path 但没有用。

我会和春天的团队核实。但到目前为止,它很有希望。

于 2015-08-03T06:13:11.993 回答
0

对于那些看不到 gwt 编译器生成的静态文件的其他人,我想为 Gokhan 的回答提供更多详细信息,因为 *.nocache.js 被请求并从他们的位置响应。

我还从https://github.com/Ekito/spring-boot-gwt示例开始,并没有看到像https://github.com/interseroh/demo-gwt-springboot那样开箱即用(我无法弄清楚它为什么起作用)。所以你应该使用

<webappDirectory>${project.build.directory}/${artifactId}/WEB-INF/classes/public</webappDirectory>

代替

 <webappDirectory>${project.build.directory}/classes/public</webappDirectory>

这是根据Gokhan的回答。此外,不要将战争留在包装部分以及战争 maven 插件中。因此,您将生成的静态文件放入实际的 /public/classes/ 文件夹中,然后将其打包到 jar 中。

于 2018-11-29T14:14:44.590 回答