简体   繁体   English

从gwt-project创建一个.war文件

[英]create a .war file from gwt-project

如何在eclipse中从我的gwt-project创建一个.war文件?

I always use Ant build file, so the project gets compiled and packaged as a war with one click. 我总是使用Ant构建文件,因此只需单击一下即可将项目编译并打包为战争。

Add an xml-file to your project with the following content: 使用以下内容将xml文件添加到项目中:

<project name="test" basedir="." default="default">
<property name="src.dir" value="src" />
<property name="build.dir" value="war" />
<path id="compile.classpath">
    <fileset dir="${build.dir}/WEB-INF/lib">
        <include name="**/*.jar" />
        <include name="**/*.xml" />
    </fileset>
</path>

<target name="default" depends="gwtc, buildwar,deploy">
</target>

<target name="gwtc" description="GWT compile to JavaScript">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        <classpath>
            <pathelement location="${src.dir}" />
            <path refid="compile.classpath" />
        </classpath>
        <arg line="-logLevel INFO" />
        <jvmarg value="-Xmx1024M" />
        <arg value="YourProject.EntryPointClass" />
    </java>
</target>

<target name="buildwar">
    <war basedir="war" destfile="YourProject.war" webxml="war/WEB-INF/web.xml">
        <exclude name="WEB-INF/**" />
        <webinf dir="war/WEB-INF/">
            <include name="**/gwt-servlet.jar" />
            <include name="**/classes/**" />
        </webinf>
    </war>
</target>

<target name="deploy">
    <copy file="YourProject.war" todir="." />
</target>

</project>

(Edit `YourProject.EntryPointClass to the path to your EntryPoint-class) (将`YourProject.EntryPointClass编辑为EntryPoint类的路径)

You would need to add gwt-user.jar and gwt-dev.jar to your projects build path(right click on your project -> Build Path -> Add External Achives). 您需要将gwt-user.jargwt-dev.jar到项目构建路径中(右键单击您的项目 - >构建路径 - >添加外部Achives)。

If you now look at your "Problems"-view you get a warning that the two files are not available on the server's class path. 如果您现在查看“问题” - 查看,您会收到一条警告,指出这两个文件在服务器的类路径中不可用。 You can use the QuickFix to either copy it to WEB-INF/lib or hide the warning. 您可以使用QuickFix将其复制到WEB-INF/lib或隐藏警告。 The build file will not include those two file in the war-file. 构建文件不会在war文件中包含这两个文件。

All you need to do to compile and create the file is to right click the xml-file and select run as Ant Build. 编译和创建文件所需要做的就是右键单击xml文件并选择run as Ant Build。

Using Eclipse: 使用Eclipse:

  1. right click the project 右键单击该项目
  2. choose Google→GWT Compile 选择Google→GWT Compile
  3. when compilation has finished, the console will say ie 编译完成后,控制台会说ie

    Linking into /home/janus/bpworkspace/gwtwerkstatt2/war/gwtwerkstatt2 链接到/ home / janus / bpworkspace / gwtwerkstatt2 / war / gwtwerkstatt2

    Link succeeded 链接成功

    Compilation succeeded -- 28.623s 编译成功 - 28.623s

  4. open a terminal and navigate to the directory 打开终端并导航到该目录

  5. create the WAR: jar cv * > /tmp/myGWTproject.war 创建WAR: jar cv * > /tmp/myGWTproject.war
  6. you can now launch it with jetty-runner or similar: java -jar jetty-runner-8.1.7.v20120910.jar /tmp/myGWTproject.war 您现在可以使用jetty-runner或类似的方式启动它: java -jar jetty-runner-8.1.7.v20120910.jar /tmp/myGWTproject.war

I just found this solution, and it's amazing :) Just install the jar and enjoy extracting to a war file. 我刚刚找到了这个解决方案,这太棒了:)只需安装jar并享受提取到war文件。

Project Site http://code.google.com/p/gwt-project-export-wizard/ 项目网站http://code.google.com/p/gwt-project-export-wizard/

One can also use webAppCreator to generate Ant build file. 也可以使用webAppCreator生成Ant构建文件。

webAppCreator ships with GWT SDK and also with Eclipse GWT Plugin. webAppCreator随附GWT SDK以及Eclipse GWT插件。 First locate GWT plugin directory 首先找到GWT插件目录

find $HOME/.eclipse/ -name "*gwt*sdk*"

this will output GWT plugin dir path. 这将输出GWT插件目录路径。 This dir has gwt dir something like gwt-2.4.0. 这个目录有gwt dir,比如gwt-2.4.0。 WebAppCreator will be in this dir. WebAppCreator将在这个目录中。 Set this dir as GWTSDK_HOME. 将此目录设置为GWTSDK_HOME。

export GWTSDK_HOME=/home/m/.eclipse/org.eclipse.platform_3.7.0_1364963873/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0

make webAppCreator executable 使webAppCreator可执行

chmod 755 $GWTSDK_HOME/webAppCreator

Now create a project using webAppCreator in some temp dir. 现在在某个临时目录中使用webAppCreator创建一个项目。

$GWTSDK_HOME/webAppCreator -out fins in.m.fins.Fins

in.m.fins.Fins is the module name. in.m.fins.Fins是模块名称。 This has to match with your project's gwt.xml in Eclipse workspace. 这必须与Eclipse工作区中项目的gwt.xml相匹配。 If your gwt.xml is src/in/m/fins/Fins.gwt.xml then module name should be in.m.fins.Fins 如果您的gwt.xml是src / in / m / fins / Fins.gwt.xml,那么模块名称应为in.m.fins.Fins

-out fins will create the project and build.xml in fins directory. -out fins将在fins目录中创建项目和build.xml。 Copy generated build.xml file to your project in Eclipse workspace. 将生成的build.xml文件复制到Eclipse工作区中的项目中。

Run war target in Eclipse Ant Window to package your project as war 在Eclipse Ant Window中运行war目标以将项目打包为war

You have to have GWT designer installed from here 你必须从这里安装GWT设计器

http://dl.google.com/eclipse/inst/d2gwt/latest/3.7 http://dl.google.com/eclipse/inst/d2gwt/latest/3.7

  1. In Eclipse on the main panel click on "Deploy module on aplication server" (It's next to blue google button). 在主面板上的Eclipse中,单击“在应用程序服务器上部署模块”(它位于蓝色google按钮旁边)。
  2. Chose war file name and location where to store it 选择war文件名和存储位置
  3. Click ok 点击确定

That's it. 而已。 Works on my GWT 2.4.0, Google Plugin for Eclipse 4.2, Eclipse Juno 适用于我的GWT 2.4.0,适用于Eclipse 4.2的Google插件,Eclipse Juno

Fist compile your project. 拳头编译你的项目。 Then: 1. Open your project. 然后:1。打开你的项目。 2. Navigate to war folder. 2.导航到war文件夹。 3. Go to File>Export>Archive File 4. Export your war FOLDER as zip file. 3.转到文件>导出>存档文件4.将您的war FOLDER导出为zip文件。 5. Change your file extension form .zip to .war 6. Keep calm and enjoy your war file. 5.将您的文件扩展名表格.zip更改为.war 6.保持冷静,享受您的战争文件。

供将来参考:您将在http://blog.elitecoderz.net/上找到有关如何使用Eclipse创建.war的另一个教程。

Compile your project. 编译您的项目。 Then: 然后:

  1. Open your project. 打开你的项目。
  2. Navigate to war folder. 导航到war文件夹。
  3. Go to File>Export>Archive File 转到文件>导出>存档文件
  4. Export your war FOLDER as zip file. 将您的战争文件夹导出为zip文件。
  5. Change your file extension form .zip to .war 将您的文件扩展名形式.zip更改为.war
  6. Keep calm and enjoy your war file. 保持冷静,享受你的战争文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM