设置 java 类路径(用于超级开发模式)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11265425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:26:42  来源:igfitidea点击:

Setting the java classpath (for super dev mode)

javagwtclasspathgwt-super-dev-mode

提问by Riley Lark

I'm trying to run a jar, gwt-codeserver.jar, in OSX.7, with the command

我正在尝试gwt-codeserver.jar使用以下命令在 OSX.7 中运行 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

The command fails with:

该命令失败:

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.run(URLClassLoader.java:202)
    ...

But gwt-dev.jar contains the definition for com.google.gwt.core.ext.TreeLogger, so I've concluded that I'm not properly setting the classpath here.

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

Am I setting the classpath correctly? The jar file is definitely the right jar and it's definitely at that location. How can I diagnose this further?

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

采纳答案by Fredrik LS

Could thisbe the source of your problem? "When you use the -jar option, the JAR file is the source of all user classes, and other user class path settings are ignored."

难道是你的问题的根源?“当您使用 -jar 选项时,JAR 文件是所有用户类的来源,其他用户类路径设置将被忽略。”

回答by Ezward

I've got the CodeServer running as an external tool in Eclipse (caveat - you still have to server your html file somehow, which I have not yet done, but this does seem to get the codeserver running). To setup the CodeServer as an external tool in Eclipse,

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

0) Remember that you should also update your module.gwt.xml file to allow Super Dev Mode book marklets and to enable source maps for debugging. Add these likes to your module.gwt.xml file.

0) 请记住,您还应该更新 module.gwt.xml 文件以允许 Super Dev Mode bookmarklets 并启用用于调试的源映射。将这些喜欢添加到您的 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) Open the External Tools/External Tools Configurations dialog; this is under the top level 'Run' menu in Windows.

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

2) Create a new configuration by selecting 'Program' in the list on the left, then press the 'New' button (it looks like a document). Name your configuration in the dialog.

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

3) The path to your java.exe file goes in the 'Location:' box. You can use the 'Browse File System' button to locate it if you don't know the path.

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

4) I left working directory blank. I'm not sure if this matters; it seems to work without it. Does anyone out there know for sure if this should be set?

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

5) The bulk of the work in in the "Arguments:" box. You will provide an argument for the class path which will include the path to gwt-dev.jar, gwt.user.jar, gwt-codeserver.jar and to your source directory. Then you will provide a -jar and argument to the gwt-codeserver.jar and the CodeServer class to run, then you will provide the arguments to CodeServer. I'll break it down;

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

5a) -cp "comma separated list of class paths, surrounded by double quotes". To make your tool definition more portable, use eclipse "Varaibles' to calculate paths that are relative to your installation. In particular, I used 'workspace_loc' for workspace relative paths (like the src directory) and 'eclipse_home' for paths to gwt SDK stuff like gwt-user.jar (because I installed the SDK in the eclipse plugins folder). Here is my classpath part;

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) Next is the name of the class that java.exe should run. This is the CodeServer class;

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

com.google.gwt.dev.codeserver.CodeServer 

5c) Next is the arguments to CodeServer. The first is the path to the src directly. For me, this is a workspace relative path;

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

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

5d) Finally, the module path (the class path to your gwt.xml file) Here is mine;

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

com.conceptua.fractiontest.FractionTest

Here is my full argument list;

这是我的完整参数列表;

-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) Select the 'Run' button to run the CodeServer. When I execute this in the console;

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 [email protected]:9876

I'm not sure why I get the initial '72 Units with compilations errors' but it seems to continue to successfully compile and run the server.

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

7) At this point, you should enter the given CodeServer url into Chrome. You will get a page that indicates the CodeServer is running and you can drag the book marklets to the bookmarks toolbar;

7) 此时,您应该在 Chrome 中输入给定的 CodeServer url。您将看到一个指示 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) The next step is to get to your html file to run it. It apparently needs to be served by a separate webserver. I'm still working on that part.

8) 下一步是进入您的 html 文件以运行它。它显然需要由单独的网络服务器提供服务。我还在做那部分。

Ed

埃德

回答by mp31415

I wasted a lot of time trying to make it work. I tried to follow wonderful Ezward instructions but my setup is probably somewhat different and it didn't work for me. There are many moving pieces and any mistake causes tons of NullPointer, StackOverflow and UnableToComplete exceptions.

我浪费了很多时间试图让它发挥作用。我试图按照 Ezward 的精彩说明进行操作,但我的设置可能有些不同,而且对我不起作用。有很多移动的部分,任何错误都会导致大量 NullPointer、StackOverflow 和 UnableToComplete 异常。

The only set of instructions that worked for me I found at http://blog.daniel-kurka.de/2012/07/mgwt-super-dev-mode.html(Daniel Kurka blog). Hope it will help somebody else who is stuck with GWT Super Dev Mode like me.

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

回答by Gal Bracha

Had the same problem. This is what helped me:

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

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

You can add the --help as such:

您可以添加 --help 如下:

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

Would output:

会输出:

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)

and then just set your -src directory and the name of your module

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

回答by sidebyeach

I was able to resolve this by adding gwt-user.jar to the classpath in addition to gwt-dev.jar. The GWT super dev mode instructionssay you might need to add gwt-user.jar.

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

回答by Sumit Singh

You can use it like following..

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

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