在Eclipse中自动添加导入时错误的包名称 [英] Wrong package name when using automatically added imports in Eclipse

查看:154
本文介绍了在Eclipse中自动添加导入时错误的包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个Maven项目转换成一个Eclipse工作区。当我在Eclipse下编辑代码时,我有时会使用 CTRL + SHIFT + M 键组合来自动将项目导入到项目类中在我的工作区但是不知何故,它们是这样添加的:

  import src.main.java.com.mycompany; 

而要导入的真实包是 com.mycompany
这必须是Eclipse中的一些配置来解决这个问题,但我很困惑。不过,这个问题很烦人。



编辑:



我忘了提到Eclipse文件是使用 mvn eclipse:eclipse 命令。



在Eclipse项目下似乎正确配置。它的源文件夹设置如下:




  • src / test / java

  • src / test / resources

  • src / main / java

  • src / main / resources



除了我按 CTRL + SHIFT + M

$ b的情况下,Eclipse下的所有内容都可以正常工作$ b

解决方案

Java项目的标准源文件夹是

  ./ src 

对于导入的maven项目,只需从源文件夹列表中删除该文件夹即可建立路径设计者正确的源文件夹是

  ./ src / main / java 


I have several Maven projects converted into one Eclipse workspace. When I edit the code under Eclipse, I sometimes use CTRL+SHIFT+M combination of keys to automatically add imports to the classes from a project in my workspace. But somehow they are added like this:

import src.main.java.com.mycompany;

while to real package I wanted to import is com.mycompany. This has to be some configuration in Eclipse to fix this but I'm confused. However, this issue is very annoying.

EDIT:

I've forgotten to mention that Eclipse files were generated using mvn eclipse:eclipse command.

Under Eclipse project seems to be configured properly. Its source folders set like this:

  • src/test/java
  • src/test/resources
  • src/main/java
  • src/main/resources

And everything under Eclipse works properly except the situation when I press CTRL+SHIFT+M keys

解决方案

The standard source folder for Java projects is

./src

For imported maven projects, simply remove this folder from the list of source folders at the build path settigs. The correct source folder is

./src/main/java

这篇关于在Eclipse中自动添加导入时错误的包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆