简体   繁体   English

这可能是由于Eclipse中的编译错误引起的

[英]This can be caused by compile errors in Eclipse

When compiling a project in idea IDE, error occurs: Error:osgi: [Test] The default package '.' 在Idea IDE中编译项目时,会发生错误:Error:osgi:[Test]默认程序包'。'。 is not permitted by the Import-Package syntax. Import-Package语法不允许使用。 This can be caused by compile errors in Eclipse because Eclipse creates valid class files regardless of compile errors. 这可能是由于Eclipse中的编译错误所致,因为Eclipse会创建有效的类文件,而与编译错误无关。 The following package(s) import from the default package null 以下包从默认包导入null

But when using Eclipse ide, it works. 但是当使用Eclipse ide时,它可以工作。 I've googled times, only found this post , but it's not my case. 我已经搜索了很多次,只找到了这篇文章,但是这不是我的情况。 I de-compiled the produced class by OSGI, there's no class has syntax like import . 我通过OSGI反编译了产生的类,没有一个类具有类似于import .语法import . Any idea for this problem? 有这个问题的主意吗?

在此处输入图片说明

Can you change package of your classes? 您可以更改课程包吗? That way eclipse will create new classes after compilation. 这样,eclipse将在编译后创建新类。 Having '.' 有“。” package is not good practice anyway. 打包不是一个好习惯。

Also, prefer different workspace for eclipse and intellij. 另外,偏爱eclipse和intellij的工作空间也不同。 Having 3 folders is good practice, one for source, one for eclipse workspace, one for intelliJ workspace. 拥有3个文件夹是一个好习惯,一个用于源文件,一个用于Eclipse工作区,一个用于智能工作区。 Each IDE creates their own files 每个IDE都会创建自己的文件

I got this error due to a Groovy script file that had import statements, but no package name at the start of the file. 由于Groovy脚本文件具有导入语句,但文件开头没有软件包名称,因此出现此错误。 I added a package name to my Groovy script, ran a clean to erase my target directory , and then the problem went away. 我在Groovy脚本中添加了程序包名称, 运行了干净的操作以擦除目标目录 ,然后问题消失了。

See answer by Hemant in this similar issue 参见Hemant 在此类似问题中的回答

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

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