简体   繁体   English

Java编译错误

[英]java compilation error

I'm expiriencing multiple compilation errors in my project, most of the code is in red, but the strange(or not) thing is that while building the project with maven everything is build successfully and the war is assemled as it should be. 我在项目中遇到多个编译错误,大多数代码为红色,但是奇怪的是,在使用maven构建项目时,一切都成功构建,战争如期进行。

The thing is that auto suggest is not working because code is not compiling. 问题是自动建议不起作用,因为代码未编译。 What can I do to fix this? 我该怎么做才能解决此问题?

I'm using eclipse, sorry 我正在使用Eclipse,对不起

UPDATE: 更新:

I've tried all suggestions below but none worked 我已经尝试了以下所有建议,但都没有用

If you are using Eclipse, try Project > clean.. your project. 如果使用的是Eclipse,请尝试“项目”>“清理..您的项目”。

I don't know why, but Eclipse sometimes just think your project was wrong but it's not. 我不知道为什么,但是Eclipse有时只是认为您的项目是错误的,但事实并非如此。 Clean it to entirely build it again. 清洁它以完全重新构建它。

You haven't specified what IDE you're using or what the errors are, which makes it pretty hard to give you advice. 您尚未指定要使用的IDE或错误是什么,这很难为您提供建议。 My guess is that you haven't configured your project (or whatever the equivalent IDE concept is) to tell it the libraries you're using... whereas the Maven build file already contains that information. 我的猜测是您尚未配置项目(或任何等效的IDE概念)来告诉它您正在使用的库...而Maven构建文件已包含该信息。

EDIT: Okay, so it can't find the right libraries. 编辑:好的,所以找不到正确的库。 Options: 选项:

  • Use a Maven plugin and let it manage the project 使用Maven插件并让其管理项目
  • Edit the project's build path and explicitly tell it which jar files to use. 编辑项目的构建路径,并明确告诉它要使用的jar文件。

Use a maven plugin in your IDE 在您的IDE中使用Maven插件

plugin for eclipse eclipse插件
plugin for netbeans Netbeans插件

If it's Eclipse do 如果是Eclipse,

Project > Clean

then right click at the parent-most project and do 然后右键单击最父项目并执行

Maven > Update Project Configuration
Maven > Update Dependencies

I guess you have m2eclipse installed, already. 我想您已经安装了m2eclipse。

Most likely you have to include external libraries/dependencies in your IDE. 您最有可能必须在IDE中包括外部库/依赖项。 It seems when you're building with maven, those dependencies are solved for you. 看来,当您使用Maven进行构建时,这些依赖关系已为您解决。

Some IDE's support Maven projects, try to see if yours does. 一些IDE支持Maven项目,请尝试查看您是否支持。

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

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