将jar添加到gwt中的ant类路径中

时间:2015-06-24 16:54:39

标签: gwt ant classpath

我是gwt和ant的新手。早些时候我正在使用maven / spring playFramework / sbt。

我想在我的gwt项目中添加一些外部罐子,如:

  • gwt3bootstrap
  • 休眠
  • mysql连接器等。

我已将jar添加到项目中的lib文件夹中:   - gwtbootstrap3-0.9.1.jar   - gwtbootstrap3-extras-0.9.1.jar

但我在控制台上收到错误:

Runing CodeServer with parameters: [-noprecompile, -port, 42543, -sourceLevel, 1.7, -bindAddress, 127.0.0.1, -launcherDir, /home/danielo/eclipseGwt/StockWatcher/war, -logLevel, INFO, com.google.gwt.sample.stockwatcher.StockWatcher]
Super Dev Mode starting up
   workDir: /tmp/gwt-codeserver-6966154251496651044.tmp
   Loading inherited module 'com.google.gwt.sample.stockwatcher.StockWatcher'
      Loading inherited module 'com.github.gwtbootstrap.Bootstrap'
         [ERROR] Unable to find 'com/github/gwtbootstrap/Bootstrap.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
Loading modules
   com.google.gwt.sample.stockwatcher.StockWatcher
      Loading inherited module 'com.google.gwt.sample.stockwatcher.StockWatcher'
         Loading inherited module 'com.github.gwtbootstrap.Bootstrap'
            [ERROR] Unable to find 'com/github/gwtbootstrap/Bootstrap.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] shell failed in doStartup method

MyProject.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6.2//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.6.2/distro-source/core/src/gwt-module.dtd">
<module rename-to='stockwatcher'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User' />

    <!-- Inherit the default GWT style sheet. You can change -->
    <!-- the theme of your GWT application by uncommenting -->
    <!-- any one of the following lines. -->
    <inherits name='com.google.gwt.user.theme.standard.Standard' />
    <inherits name="com.github.gwtbootstrap.Bootstrap" />
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
    <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->

    <!-- Other module inherits -->

    <!-- Specify the app entry point class. -->
    <entry-point class='com.google.gwt.sample.stockwatcher.client.StockWatcher' />
</module>

的build.xml:

<?xml version="1.0" encoding="utf-8" ?>
<project name="StockWatcher" default="build" basedir=".">
    <!-- Configure path to GWT SDK -->
    <property name="gwt.sdk" location="/path/to/gwt.sdk" />

    <path id="project.class.path">
        <pathelement location="war/WEB-INF/classes" />
        <pathelement location="${gwt.sdk}/gwt-user.jar" />
        <fileset dir="${gwt.sdk}" includes="gwt-dev*.jar" />
        <!-- Add any additional non-server libs (such as JUnit) -->
        <fileset dir="war/WEB-INF/lib" includes="**/*.jar" />
    </path>

    <target name="libs" description="Copy libs to WEB-INF/lib">
        <mkdir dir="war/WEB-INF/lib" />
        <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
        <!-- Add any additional server libs that need to be copied -->
    </target>

    <target name="javac" depends="libs" description="Compile java source">
        <mkdir dir="war/WEB-INF/classes" />
        <javac srcdir="src" includes="**" encoding="utf-8" destdir="war/WEB-INF/classes" source="1.5" target="1.5" nowarn="true" debug="true" debuglevel="lines,vars,source">
            <classpath refid="project.class.path" />
        </javac>
        <copy todir="war/WEB-INF/classes">
            <fileset dir="src" excludes="**/*.java" />
        </copy>
    </target>

    <target name="gwtc" depends="javac" description="GWT compile to JavaScript">
        <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
            <classpath>
                <pathelement location="src" />
                <path refid="project.class.path" />
            </classpath>
            <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
            <jvmarg value="-Xmx256M" />
            <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
            <arg value="com.google.gwt.sample.stockwatcher.StockWatcher" />
        </java>
    </target>

    <target name="devmode" depends="javac" description="Run development mode">
        <java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
            <classpath>
                <pathelement location="src" />
                <path refid="project.class.path" />
            </classpath>
            <jvmarg value="-Xmx256M" />
            <arg value="-startupUrl" />
            <arg value="StockWatcher.html" />
            <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
            <arg value="com.google.gwt.sample.stockwatcher.StockWatcher" />
        </java>
    </target>

    <target name="javac.tests" depends="javac" description="Compiles test code">
        <javac srcdir="test" includes="**" encoding="utf-8" source="1.5" target="1.5" nowarn="true" debug="true" debuglevel="lines,vars,source">
            <classpath location="path_to_the_junit_jar" />
            <classpath refid="project.class.path" />
        </javac>
    </target>

    <target name="test.dev" depends="javac.tests" description="Run development mode tests">
        <mkdir dir="reports/htmlunit.dev" />
        <junit fork="yes" printsummary="yes" haltonfailure="yes">
            <jvmarg line="-Xmx256m" />
            <sysproperty key="gwt.args" value="-logLevel WARN" />
            <sysproperty key="java.awt.headless" value="true" />
            <classpath>
                <pathelement location="src" />
                <pathelement location="test" />
                <path refid="project.class.path" />
                <pathelement location="path_to_the_junit_jar" />
            </classpath>
            <batchtest todir="reports/htmlunit.dev">
                <fileset dir="test">
                    <include name="**/*Test.java" />
                </fileset>
            </batchtest>
            <formatter type="plain" />
            <formatter type="xml" />
        </junit>
    </target>

    <target name="test.prod" depends="javac.tests" description="Run production mode tests">
        <mkdir dir="reports/htmlunit.prod" />
        <junit fork="yes" printsummary="yes" haltonfailure="yes">
            <jvmarg line="-Xmx256m" />
            <sysproperty key="gwt.args" value="-prod -logLevel WARN -out www-test" />
            <sysproperty key="java.awt.headless" value="true" />
            <classpath>
                <pathelement location="src" />
                <pathelement location="test" />
                <path refid="project.class.path" />
                <pathelement location="path_to_the_junit_jar" />
            </classpath>
            <batchtest todir="reports/htmlunit.prod">
                <fileset dir="test">
                    <include name="**/*Test.java" />
                </fileset>
            </batchtest>
            <formatter type="plain" />
            <formatter type="xml" />
        </junit>
    </target>

    <target name="test" description="Run development and production mode tests">
        <antcall target="test.dev" />
        <antcall target="test.prod" />
    </target>

    <target name="hosted" depends="devmode" description="Run development mode (NOTE: the 'hosted' target is deprecated)" />

    <target name="build" depends="gwtc" description="Build this project" />

    <target name="war" depends="build" description="Create a war file">
        <zip destfile="StockWatcher.war" basedir="war" />
    </target>

    <target name="clean" description="Cleans this project">
        <delete dir="war/WEB-INF/classes" failonerror="false" />
        <delete dir="war/stockwatcher" failonerror="false" />
    </target>

</project>

我也尝试在项目中使用eclipse RMB添加这个罐子 - &gt;属性 - &gt; Java构建路径 - &gt; “库”选项卡 - &gt;添加外部JAR

但它没有帮助我。

请给我一些帮助。

我搜索了许多论坛帖子时遇到同样的问题,但无法自行解决。

1 个答案:

答案 0 :(得分:0)

只需使用gwtBootstrap3,你必须为它下载jar! here the link

比你必须在build.xml中声明pathelement

<path id="project.class.path">
        <pathelement location="war/WEB-INF/classes" />
        <pathelement location="${gwt.sdk}/gwt-user.jar" />
        <pathelement location="yourpathtojar/gwtbootstrap3-0.9.1.jar" />
        <fileset dir="${gwt.sdk}" includes="gwt-dev*.jar" />
        <!-- Add any additional non-server libs (such as JUnit) -->
        <fileset dir="war/WEB-INF/lib" includes="**/*.jar" />
    </path>

如果您使用maven项目,则可以关注this example