Eclipse在项目构建路径中忘记了Java库(Eclipse forgets Java library in project build path)

编程入门 行业动态 更新时间:2024-10-26 22:19:52
Eclipse在项目构建路径中忘记了Java库(Eclipse forgets Java library in project build path)

一位同事为我正在处理的Android应用程序提供了第二个包,并且在类中导入了几个“java.awt”和“javax.swing”导入,这些导入全部用红色“x”标记。

Eclipse(Mars.2,4.5.2)已经知道安装了哪些Java版本(Window - Preferences - Java - 安装的JRE,“jdk1.8.0_161”旁边有一个复选标记),我只是检查了JAVA_HOME环境变量是否仍然在那里(它是)。 为了解决这个问题,我仍然需要将JRE系统库(1.8.0 v161)添加到项目的构建路径中。

实际的问题是:每次我重新启动Eclipse时,红色的“x”都回来了,我必须再次添加Java。

我如何避免Eclipse忘记库?

编辑:我的项目的类路径说:

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="gen"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin/classes"/> </classpath>

A co-worker gave me a second package for an Android app I'm working on and there are a couple of "java.awt" and "javax.swing" imports in the classes, which were all marked with red "x".

Eclipse (Mars.2, 4.5.2) already knows what Java versions are installed (Window - Preferences - Java - Installed JREs, "jdk1.8.0_161" has a checkmark next to it) and I just checked if the JAVA_HOME environment variable is still there (which it is). To fix the problem, I still had to add a JRE system library (1.8.0 v161) to the project's build path.

The actual problem is: Every time I restart Eclipse, the red "x" are back and I have to add Java again.

How can I keep Eclipse from forgetting the library?

Edit: The classpath for my project says:

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="gen"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin/classes"/> </classpath>

最满意答案

java.awt和javax.swing都不是Android API的一部分(因为Android使用自己的UI工具包)。 您可以通过添加外部JAR ...将JRE / JDK的lib/rt.jar 添加到您的Java构建路径中,但这是一个肮脏的窍门。

Neither java.awt nor javax.swing are part of the Android API (because Android uses its own UI toolkit). You can add a JRE/JDK's lib/rt.jar via Add External JARs... to your Java Build Path, but that's a dirty trick.

更多推荐

本文发布于:2023-07-28 18:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1307961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   忘记了   项目   Java   Eclipse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!