Eclipse包声明工作? [英] Eclipse Package Declaration Work Around?

查看:205
本文介绍了Eclipse包声明工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在工作的团队不使用eclipse,希望以某种方式设置src文件夹。另一方面,我正在使用日食。他们希望src文件夹具有以下结构:src / main / java / com / *但是,他们希望包声明中只有com。*。如果我转到project->属性,并在source选项卡中删除src文件夹作为源文件夹,然后_only添加com。*文件夹作为source_的一部分,它将显示com。*作为一个包,但我仍然必须将src中的整个路径添加到.java文件中。以下是我为了使eclipse识别软件包所必须做的一个例子:

  package main.java.com.parser ; 

团队想要的是拥有主要和 java 只是一个文件夹,所以包声明只是:

  package com.parser; 

所以尽管文件结构仍然是src / main / java / com / parser,将在后面的例子中说明。



有没有办法在eclipse中这样做? 我已经看到有人在这里提出类似的问题,但他们似乎并不关心整个路径必须是包裹声明的一部分。



我宁愿不这样做,但是没有人在这个项目上使用eclipse。



感谢您提前提供任何帮助。 >

解决方案

在包资源管理器中,右键单击 src 文件夹,然后选择构建路径>从构建路径中删除



然后找到src / main / java文件夹,右键单击 java ,然后选择Build Path>用作源文件夹



基本上这告诉eclipse, java 是包含包和源文件的文件夹。 / p>

PS这是一个非常正常的使用Maven构建的项目设置。如果您下载m2e(Maven到Eclipse)插件并选择创建Maven项目(或从pom.xml导入),那么Eclipse将自动知道如何正确找到源文件夹。


The team in which I'm working doesn't use eclipse and wants the src folder to be setup a certain way. I, on the other hand, am using eclipse. They would like the src folder to have, for example, the following structure: src/main/java/com/* However, they would like package declarations to only have com.* in them. If I go to project->properties and in the source tab remove the src folder as a source folder and then _only add the com.* folder as part of the source_ it will show com.* as a package, but I still have to add the whole path from src down in the .java files. Here's an example of what I have to do in order for eclipse to recognize the packages:

package main.java.com.parser;

And what the team wants is to have main and java just be a folder so the package declaration would just be:

package com.parser;

So although the file structure would still be src/main/java/com/parser, the package name would be as stated in the later example.

Is there a way to do this in eclipse? I've seen some people asking similar questions on here, but they seem to have no concern that the whole path must be part of the package declaration.

I would much prefer not to do this this way, but no one else is using eclipse on this project.

Thanks for any help in advance.

解决方案

In the Package Explorer, right click the src folder and select Build Path > Remove from Build Path

Then find the src/main/java folder, right click java and select Build Path > Use as Source Folder

Basically this tell eclipse that java is the folder which contains the packages and source files.

P.S. This is a very normal project setup for building with Maven. If you download the m2e (Maven to Eclipse) plugins and choose to create a Maven Project (or import from the pom.xml) then Eclipse will automatically know how to correctly locate the source folder.

这篇关于Eclipse包声明工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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