【问题标题】:Setting the java classpath (for super dev mode)设置 java 类路径(用于超级开发模式)
【发布时间】:2012-07-01 04:47:55
【问题描述】:

我正在尝试使用命令在 OSX.7 中运行一个 jar,gwt-codeserver.jar

java -cp ".:/sdk/gwt-2.5.0.rc1/gwt-dev.jar" -jar /sdk/gwt-2.5.0.rc1/gwt-codeserver.jar com.activegrade.TeacherView

命令失败:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gwt/core/ext/TreeLogger
Caused by: java.lang.ClassNotFoundException: com.google.gwt.core.ext.TreeLogger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    ...

但是 gwt-dev.jar 包含 com.google.gwt.core.ext.TreeLogger 的定义,所以我得出的结论是我没有在此处正确设置类路径。

我是否正确设置了类路径? jar 文件绝对是正确的 jar,它肯定在那个位置。如何进一步诊断?

【问题讨论】:

    标签: java gwt classpath gwt-super-dev-mode


    【解决方案1】:

    我已经让 CodeServer 作为 Eclipse 中的外部工具运行(警告 - 您仍然必须以某种方式提供您的 html 文件,我还没有这样做,但这似乎确实让 codeserver 运行)。要将 CodeServer 设置为 Eclipse 中的外部工具,

    0) 请记住,您还应该更新您的 module.gwt.xml 文件以允许超级开发模式书签标记并启用源映射以进行调试。将这些喜欢添加到您的 module.gwt.xml 文件中。

    <!-- enable the SuperDevMode book marklets  -->
    <add-linker name="xsiframe"/>
    <set-configuration-property name="devModeRedirectEnabled" value="true"/>
    
    <!--  enable source maps -->
    <set-property name="compiler.useSourceMaps" value="true" />
    

    1) 打开外部工具/外部工具配置对话框;这是在 Windows 的顶级“运行”菜单下。

    2) 通过选择左侧列表中的“程序”来创建新配置,然后按“新建”按钮(它看起来像一个文档)。在对话框中命名您的配置。

    3) java.exe 文件的路径位于“位置:”框中。如果您不知道路径,可以使用“浏览文件系统”按钮来定位它。

    4) 我将工作目录留空。我不确定这是否重要;没有它似乎可以工作。有没有人知道这是否应该设置?

    5) “参数:”框中的大部分工作。您将为类路径提供一个参数,其中包括 gwt-dev.jar、gwt.user.jar、gwt-codeserver.jar 和源目录的路径。然后,您将为 gwt-codeserver.jar 和要运行的 CodeServer 类提供一个 -jar 和参数,然后您将向 CodeServer 提供参数。我会分解它;

    5a) -cp "逗号分隔的类路径列表,用双引号括起来"。为了使您的工具定义更具可移植性,请使用 eclipse“Varaibles”来计算与您的安装相关的路径。特别是,我使用“workspace_loc”作为工作空间的相对路径(如 src 目录),使用“eclipse_home”作为 gwt SDK 的路径gwt-user.jar 之类的东西(因为我在 eclipse 插件文件夹中安装了 SDK)。这是我的类路径部分;

    -cp "${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-user.jar;${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-dev.jar;${workspace_loc:\GWTFractionTest\war\WEB-INF\lib\gwtquery-1.1.0.jar};${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-codeserver.jar"
    

    5b) 接下来是 java.exe 应该运行的类的名称。这是 CodeServer 类;

    com.google.gwt.dev.codeserver.CodeServer 
    

    5c) 接下来是 CodeServer 的参数。第一个是直接指向 src 的路径。对我来说,这是一个工作区相对路径;

    -src "${workspace_loc:\GWTFractionTest\src}" 
    

    5d) 最后,模块路径(gwt.xml 文件的类路径)这是我的;

    com.conceptua.fractiontest.FractionTest
    

    这是我的完整参数列表;

    -cp "${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-user.jar;${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-dev.jar;${workspace_loc:\GWTFractionTest\war\WEB-INF\lib\gwtquery-1.1.0.jar};${eclipse_home}plugins\gwt-2.5.0.rc1\gwt-2.5.0.rc1\gwt-codeserver.jar" com.google.gwt.dev.codeserver.CodeServer -src "${workspace_loc:\GWTFractionTest\src}" com.conceptua.fractiontest.FractionTest
    

    6) 选择“运行”按钮运行 CodeServer。当我在控制台中执行此操作时;

    workDir: C:\Users\Ezward\AppData\Local\Temp\gwt-codeserver-6942784883227417581.tmp
    binding: user.agent=safari
    binding: compiler.useSourceMaps=true
    binding: locale=en
    Compiling module com.conceptua.fractiontest.FractionTest
       Validating units:
          Ignored 72 units with compilation errors in first pass.
    Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
       Computing all possible rebind results for 'com.google.gwt.useragent.client.UserAgentAsserter'
          Rebinding com.google.gwt.useragent.client.UserAgentAsserter
             Checking rule <generate-with class='com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator'/>
                [WARN] Detected warnings related to 'com.google.gwt.editor.client.SimpleBeanEditorDriver'.   Are validation-api-<version>.jar and validation-api-<version>-sources.jar on the classpath?
                Specify -logLevel DEBUG to see all errors.
                [WARN] Unknown type 'com.google.gwt.editor.client.SimpleBeanEditorDriver' specified in deferred binding rule
       Compiling 1 permutation
          Compiling permutation 0...
          Source Maps Enabled
       Compile of permutations succeeded
    Linking into C:\Users\Ezward\AppData\Local\Temp\gwt-codeserver-6942784883227417581.tmp\com.conceptua.fractiontest.FractionTest\compile-1\war\fractiontest; Writing extras to C:\Users\Ezward\AppData\Local\Temp\gwt-codeserver-6942784883227417581.tmp\com.conceptua.fractiontest.FractionTest\compile-1\extras\fractiontest
       Link succeeded
       Compilation succeeded -- 58.257s
    Compile completed in 60831 ms
    2012-07-01 12:37:03.184::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
    2012-07-01 12:37:03.185::INFO:  jetty-6.1.x
    
    The code server is ready.
    Next, visit: http://localhxst:9876/
    2012-07-01 12:37:03.274::INFO:  Started SelectChannelConnector@127.0.0.1:9876
    

    我不确定为什么我会收到最初的“72 个带有编译错误的单元”,但它似乎继续成功编译和运行服务器。

    7) 此时,您应该将给定的 CodeServer url 输入到 Chrome 中。您将获得一个指示 CodeServer 正在运行的页面,您可以将书签标记拖到书签工具栏;

    GWT Code Server
    Drag these two bookmarklets to your browser's bookmark bar:
    Dev Mode On Dev Mode Off
    Visit a web page that uses one of these modules:
    fractiontest
    Click "Dev Mode On" to start development mode.
    

    8) 下一步是访问您的 html 文件以运行它。它显然需要由单独的网络服务器提供服务。我仍在努力。

    埃德

    【讨论】:

      【解决方案2】:

      this 可能是您问题的根源吗? "使用-jar选项时,JAR文件是所有用户类的来源,其他用户类路径设置被忽略。"

      【讨论】:

        【解决方案3】:

        我浪费了很多时间试图让它发挥作用。我尝试遵循美妙的 Ezward 说明,但我的设置可能有些不同,它对我不起作用。有许多移动部件,任何错误都会导致大量 NullPointer、StackOverflow 和 UnableToComplete 异常。

        我在http://blog.daniel-kurka.de/2012/07/mgwt-super-dev-mode.html(Daniel Kurka 博客)找到了唯一对我有用的说明。希望它能帮助像我这样被 GWT 超级开发模式困扰的其他人。

        【讨论】:

          【解决方案4】:

          你可以像下面这样使用它..

          java -cp ".:/sdk/gwt-2.5.0.rc1/gwt-dev.jar:/sdk/gwt-2.5.0.rc1/gwt-codeserver.jar" com.activegrade.TeacherView
          

          【讨论】:

            【解决方案5】:

            遇到了同样的问题。这对我有帮助:

            java -cp "./gwt-codeserver.jar:./gwt-dev.jar" com.google.gwt.dev.codeserver.CodeServer
            

            您可以像这样添加--help:

            java -cp "./gwt-codeserver.jar:./gwt-dev.jar" com.google.gwt.dev.codeserver.CodeServer --help
            

            会输出:

            CodeServer [-bindAddress address] [-port port] [-workDir dir] [-src dir] [module]
            
            where 
              -bindAddress  The ip address of the code server. Defaults to 127.0.0.1.
              -port         The port where the code server will run.
              -workDir      The root of the directory tree where the code server willwrite compiler output. If not supplied, a temporary directorywill be used.
              -src          A directory containing GWT source to be prepended to the classpath for compiling.
            and 
              module        The GWT modules that the code server should compile. (Example: com.example.MyApp)
            

            然后只需设置您的 -src 目录和模块的名称

            【讨论】:

              【解决方案6】:

              除了 gwt-dev.jar 之外,我还可以通过将 gwt-user.jar 添加到类路径来解决此问题。 GWT超级开发模式instructions说你可能需要添加gwt-user.jar。

              【讨论】:

                猜你喜欢
                • 2014-06-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2021-09-07
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多