Java 错误:编译 GWT 项目时无法找到或加载主类 com.google.gwt.dev.Compiler
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22537795/
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
Error: Could not find or load main class com.google.gwt.dev.Compiler while compiling a GWT project
提问by Mayur Jadhav
Whenever I try to compile any of my GWT application the compilation fails with the error message "Error: Could not find or load main class com.google.gwt.dev.Compiler". This problem started after I made some changes to the path and classpath environment variables while installing Tomcat, I don't know whether these changes caused the problem. I tried to reinstall GWT plugin but all in vain. Any help would be greatly appreciated. I am using Eclipse 4.3 and GWT SDK 2.6.0.
每当我尝试编译任何 GWT 应用程序时,编译都会失败并显示错误消息“错误:无法找到或加载主类 com.google.gwt.dev.Compiler”。这个问题是我在安装Tomcat的时候对path和classpath环境变量做了一些修改后出现的,不知道是不是这些修改导致的问题。我试图重新安装 GWT 插件,但徒劳无功。任何帮助将不胜感激。我正在使用 Eclipse 4.3 和 GWT SDK 2.6.0。
采纳答案by outellou
Try Run As > Run Configurations
, delete the current configuration by clicking on the X top left. Apply and close. Now, Run As > Web application
. A default configuration will be created.
尝试Run As > Run Configurations
,单击左上角的 X 删除当前配置。应用并关闭。现在,Run As > Web application
。将创建默认配置。
If you have any VM arguments, copy them before doing the steps above.
如果您有任何 VM 参数,请在执行上述步骤之前复制它们。
回答by Braj
Check things as mentioned in below snapshots:
检查以下快照中提到的内容:
check whether Main class
is having value com.google.gwt.dev.DevMode
or not.
检查是否Main class
有价值com.google.gwt.dev.DevMode
。
Go To Run Configuration >
转到运行配置 >
Go To Project Properties > Build Path
转到项目属性 > 构建路径
Check whether GWT SDK is installed properly or not
检查 GWT SDK 是否安装正确
回答by Andrei Volgin
Check your Run Configuration > Arguments. They are not updated automatically when you make changes to classpath. Make sure your main class is referenced correctly in the arguments.
检查您的运行配置 > 参数。当您更改类路径时,它们不会自动更新。确保在参数中正确引用了您的主类。
回答by Knarf
I would recommend creating maven or ant scripts to build outside eclipse.
我建议创建 maven 或 ant 脚本以在 eclipse 之外构建。
This way other developers in your team, that maybe don't use eclipse can also build/run the application.
这样,您团队中可能不使用 eclipse 的其他开发人员也可以构建/运行应用程序。
回答by Chethaka Uduwarage
I had the same error in IntelliJ and following steps solved my problem.
我在 IntelliJ 中遇到了同样的错误,以下步骤解决了我的问题。
(In IntelliJ) Go to File --> Project Structure --> Facets (Under project settings)
If GWT has set for web facet remove it
(在 IntelliJ 中)转到文件 --> 项目结构 --> 构面(在项目设置下)
如果 GWT 已设置为 web facet 将其删除
After removing this GWT facet my project compile and run without a problem.
删除此 GWT 方面后,我的项目可以正常编译并运行。
回答by shyangs
set the "classpath" environment variable = %gwt_installed_dir%
设置“类路径”环境变量 = %gwt_installed_dir%
回答by May
I came across this problem on an old GWT project that was using GWT version 2.4.0 rather than the current 2.8.2. I think older versions of GWT run with legacy/classic development mode. They run the main class in com.google.gwt.dev.DevMode found in gwt-dev.jar.
我在使用 GWT 版本 2.4.0 而不是当前的 2.8.2 的旧 GWT 项目中遇到了这个问题。我认为旧版本的 GWT 以传统/经典开发模式运行。它们运行在 gwt-dev.jar 中的 com.google.gwt.dev.DevMode 中的主类。
The error is actually what it says it is. DevMode exists in gwt-dev.jar. You're missing gwt-dev.jar somewhere in your classpath. You either need to add it as a maven dependency in your pom.xml and then update your maven dependencies like so:
错误实际上就是它所说的那样。DevMode 存在于 gwt-dev.jar 中。您在类路径中的某处缺少 gwt-dev.jar。您要么需要将其添加为 pom.xml 中的 maven 依赖项,然后像这样更新您的 maven 依赖项:
- In pom.xml:
- 在 pom.xml 中:
<properties>
<!-- this should be whatever version you are using -->
<gwt.version>2.4.0</gwt.version>
</properties>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwt.version}</version>
</dependency>
- Update dependencies.
- 更新依赖项。
In Eclipse, right click project → maven → “update project...” → tick ‘force update of snapshot/releases' (just cause you want to be thorough. It's probably not necessary in this case though). → press OK button.
在 Eclipse 中,右键单击项目 → maven → “更新项目...” → 勾选“强制更新快照/发布”(只是因为您想要彻底。不过在这种情况下可能没有必要)。→ 按确定按钮。
OR check that you have gwt-dev.jar somewhere in your classpath:
或者检查您的类路径中是否有 gwt-dev.jar:
- In Eclipse, right click project → build path → configure build path → libraries tab → make sure you either have the GWT SDK added as a library, or that gwt-dev.jar exists somewhere in your maven dependencies.
- 在 Eclipse 中,右键单击项目 → 构建路径 → 配置构建路径 → 库选项卡 → 确保您将 GWT SDK 添加为库,或者 gwt-dev.jar 存在于您的 maven 依赖项中的某处。