简体   繁体   English

如何在包名中添加前缀?

[英]How to add prefix to package names?

I've got 45 java packages I've imported into a src folder in Eclipse. 我已经将45个Java软件包导入了Eclipse中的src文件夹。 Each of course has a particular name, and contains numerous java files. 当然每个都有一个特定的名称,并且包含许多Java文件。 Problem is that the import statements in the packages' classes all refer to the various packages (including themselves in the package line) with an initial prefix name. 问题在于,包类中的import语句全部以初始前缀名称引用各种包(包括它们本身在package行中)。

So for example, if the package name is snowman.image the java files within start with abc.snowman.image and refer to another package named snowball.hit as abc.snowball.hit . 因此,例如,如果包名称为snowman.image ,则snowman.image的java文件以abc.snowman.image开头, abc.snowman.image另一个名为snowball.hit包称为abc.snowball.hit Needless to say, Eclipse complains that these packages referred to in the code do not exist. 不用说,Eclipse抱怨代码中引用的这些软件包不存在。

I'm thinking I must've done something wrong. 我在想我一定做错了什么。 Did I import the packages incorrectly? 我没有正确导入软件包吗? Can I change some property so that the prefix is understood before the packages' names. 我可以更改一些属性,以便在软件包名称之前理解前缀。 I'd rather not go through hundreds of java files and manually change the package and import names. 我宁愿不要浏览数百个Java文件并手动更改packageimport名称。

First you need to make sure that the project configuration is correct. 首先,您需要确保项目配置正确。 Right click on the project, then go to "properties", and in the tree on the left select "java build path". 右键单击该项目,然后转到“属性”,然后在左侧的树中选择“ java构建路径”。 Switch to the "source" tab and and make sure then you have the "your project/src" as a source folder. 切换到“源”选项卡,并确保然后将“您的项目/ src”作为源文件夹。 Starting from the "src" folder you will have the package names just as Tom commented on your question. 从“ src”文件夹开始,您将获得包名称,就像Tom在问题上发表的评论一样。

Also eclipse has some nice feature, such as "organize imports" - default shortcut ctrl+shift+o - which will look through your source files and update your imports. eclipse还具有一些不错的功能,例如“组织导入”-默认快捷键ctrl + shift + o-它将浏览您的源文件并更新您的导入。 This works both in the text editor for the current class, as also from the "navigator/package explorer" view for the entire. 这既可以在当前类的文本编辑器中使用,也可以在整个“导航器/包资源管理器”视图中使用。 selected project. 选定的项目。

Please make a backup of your project before trying this, as it will automatically change your files by removing unused and adding the imports it finds in your current structure so you might end up with snowball.hit instead of your desired abc.snowball.hit . 请先备份您的项目,然后再尝试删除该项目,因为它会通过删除未使用的文件并添加在当前结构中找到的导入内容来自动更改文件,因此您最终可能会使用snowball.hit而不是所需的abc.snowball.hit

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

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