我的GWT應用程序目前使用maven打包成一場戰爭,然後部署到tomcat。我想更改爲使用jar包進行打包,以便可以使用java -jar執行,並通過嵌入式Web服務器(如Jetty)提供應用程序。與在開發模式下運行時發生的情況類似,但我希望它從包含html和GWT js文件的單個易於部署的fat/uber jar發生。我只能在春季爲Jetty找到這樣的說明,而且還沒有能夠適應GWT。像Jetty's example uber jar project這樣的東西很接近,只需要與GWT一起工作。如何使用maven將GWT應用程序打包在胖JAR中?
0
A
回答
0
您可以簡單地改變你的Maven項目的包裝:
<project>
...
<packaging>jar</packaging>
...
</project>
請注意,您couldnt deploy a jar file in tomcat。
接下來我會確保依賴關係gwt-dev
提供了作用域(因爲這個依賴包含已經舊版本的jetty)。之後,您可以添加運動衫依賴項並啓動一個嵌入式服務器,該服務器爲您的GWT應用程序提供服務(例如see here)。
0
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.project</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
+0
感謝您的回答,但這並不包括我問過的所有東西,即GWT編譯jar,嵌入式web服務器等js文件。 –
0
結合example Jetty project和@ mam10eks答案,我想我已經成功反正弄明白一個簡單的GWT應用程序:
的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>com.example.HelloJettyGwt</groupId>
<artifactId>HelloJettyGwt</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>HelloJettyGwt</name>
<properties>
<gwtVersion>2.7.0</gwtVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty-version>9.3.2.v20150730</jetty-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>${gwtVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>${jetty-version}</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>app.html</runTarget>
<modules>
<module>com.example.HelloJettyGwt.app</module>
</modules>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>
src/main/webapp
</directory>
<filtering>true</filtering>
<includes>
<include>**/*.html</include>
<include>**/*.css</include>
<include>**/web.xml</include>
</includes>
</resource>
<resource>
<directory>
${project.build.directory}/${project.build.finalName}/
</directory>
<filtering>true</filtering>
<includes>
<include>**/app/**</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<mainClass>com.example.HelloJettyGwt.ServerMain</mainClass>
</manifest>
<manifestEntries>
<Implementation-Version>${jetty-version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>rebuild-war</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/VERSION.txt</exclude>
<exclude>META-INF/LICENSE.txt</exclude>
</excludes>
</filter>
<!-- exclude the MANIFEST.MF entries that will cause problems -->
<filter>
<artifact>javax.annotation:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
<filter>
<artifact>javax.servlet:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
<filter>
<artifact>javax.websocket:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
<filter>
<artifact>org.eclipse.jetty:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
<filter>
<artifact>org.eclipse.jetty.websocket:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
<filter>
<artifact>org.ow2.asm:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.0.0,)</version>
</requireMavenVersion>
<requireJavaVersion>
<version>[1.8,)</version>
<message>[ERROR] OLD JDK [${java.version}] in use.
Jetty
${jetty-version} requires JDK 1.8 or newer</message>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
主要方法:
Server server = new Server(8080);
URL webRootLocation = this.getClass().getResource("/app.html");
if (webRootLocation == null)
{
throw new IllegalStateException("Unable to determine webroot URL location");
}
URI webRootUri = URI.create(webRootLocation.toURI().toASCIIString().replaceFirst("/app.html$","/"));
WebAppContext altHandler = new WebAppContext();
altHandler.setResourceBase(Resource.newResource(webRootUri).toString());
altHandler.setDescriptor(Resource.newResource(webRootUri).toString() + "WEB-INF/web.xml");
altHandler.setContextPath("/");
altHandler.setParentLoaderPriority(true);
server.setHandler(altHandler);
server.start();
server.join();
}
+0
剛發現雖然這與mvn package && java -jar一起工作,但它不起作用超級開發模式通過mvn gwt:run –
相關問題
- 1. 如何使用Maven將GWT模塊打包爲Jar文件?
- 2. 使用Maven EAR打包的GWT應用程序運行SuperDevMode
- 3. 如何將gwt應用程序打包爲maven中的war文件?
- 4. maven-gwt-plugin和打包到JAR
- 5. 如何使用maven將我的web應用程序和tomcat打包在一起?
- 6. 在Netbeans中將Jython應用程序打包爲JAR
- 7. 如何將我的測試包含在應用程序jar中
- 8. 如何在包含javadoc的單個jar包中使用maven程序集插件
- 9. Spring Boot Maven - 無法將Web應用程序打包爲可執行的jar/war
- 10. 如何使用Maven運行Ext GWT(GXT)應用程序
- 11. 如何使用maven打包jar中的依賴關係?
- 12. 如何在Maven應用程序中包含非maven Netbeans模塊?
- 13. Tomcat上的Maven Java應用程序NoClassDefFoundError即使包含Jar
- 14. 使用Maven將JSF複合組件自動打包到JAR中
- 15. 在使用maven的tar程序集中包含Jar依賴項
- 16. 如何在maven程序集中包含rmic包jar
- 17. Runtime.exec應用程序打包在同一個jar(在Win中)?
- 18. 如何將jar文件包含到iphone應用程序中
- 19. 使用maven,如何在包中包含jar依賴項?
- 20. 如何使用Netbeans和Maven將網頁碎片打包到jar中
- 21. 如何打包和使用自定義taglib(maven jar項目)
- 22. 如何使用我的Android應用程序並打包JAR文件?
- 23. 在胖JAR中包含源碼
- 24. 使用maven在Jar中打包JavaScript文件?
- 25. gwt應用程序可以轉換/打包爲Windows通用應用程序嗎?
- 26. 使用Maven在單獨的jar中構建和打包應用程序和依賴關係
- 27. Gradle - 爲Groovy應用程序創建一個胖JAR
- 28. 如何在GWT離線應用程序中包含外部Javascript
- 29. 如何使用Maven在RCP應用程序中使用log4j?
- 30. 如何將Android Gradle應用程序打包爲* .jar或* .aar文件
謝謝我已經嘗試了鏈接,它幫助我靠得更近,但是我仍然無法使用maven一切工作,並且我在解決方法之後可以獲得胖子jar即一切需要在罐子裏運行webapp,包括html,GWT js文件等,而不需要單獨的war文件。 –