问题描述
我想配置Spring Boot Embedded Servlet Container + GWT.我想要的方式是创建一个 jar/war 文件,它只包含已编译的 gwt 文件 &静态资源.我想从 lib/* 加载 jars,并从 classpath 加载配置文件.
I want to configure Spring Boot Embedded Servlet Container + GWT. The way I want is either create a jar/war file that just contains the compiled gwt files & static resources. I want to load jars from lib/* and config files from classpath.
我找不到任何工作示例.实际上有一个,https://github.com/Ekito/spring-boot-gwt,但是所有的依赖项和配置仍在战争中.
I couldn't find any working example. There is one actually, https://github.com/Ekito/spring-boot-gwt, but all the dependencies and configs are still in the war.
有人可以提出解决方案吗?
Can someone suggest a solution ?
推荐答案
经过长时间的搜索&测试,这是我想出的解决方案:
After long search & test, here is the solution that I come up with:
```
<!-- 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,除了一些小改动:
my project structure is is same with original project, https://github.com/Ekito/spring-boot-gwt, except some little changes:
- 代替 webapp 文件夹,我有 src/main/resources/public 文件夹和 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-limitations.
As a result, I have a runable jar, but run by org.springframework.boot.loader.PropertiesLauncher. Single jar works as expected, Tomcat doesnt work as stated here: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-jsp-limitations.
另外,我可以将 lib 文件夹移到 jar 文件之外,但是为了设置 loader.path
属性,我需要将它放到 jar 文件中的 application.properties 中.我应该可以使用 -Dloader.path 但没有用.
Also, I can move the lib folder outside the jar file, but I in order to set the loader.path
property, I need to put it to application.properties inside the jar file. I should be able to use -Dloader.path but didn't work.
我会与 Spring 团队核实.但到目前为止,它很有希望.
I'll check with spring team. But so far, it's promising.
这篇关于Spring Boot + GWT 嵌入式配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!