简体   繁体   English

Eclipse忘记了项目构建路径中的Java库

[英]Eclipse forgets Java library in project build path

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". 一位同事为我提供了我正在使用的Android应用程序的第二个软件包,并且在类中有几个“ java.awt”和“ javax.swing”导入,它们都标记为红色“ 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). Eclipse(Mars.2、4.5.2)已经知道安装了哪些Java版本(Window-Preferences-Java-Installed JRE,“ jdk1.8.0_161”旁边有一个对号),我只是检查了JAVA_HOME环境变量是否为仍然在那里(它是)。 To fix the problem, I still had to add a JRE system library (1.8.0 v161) to the project's build path. 要解决此问题,我仍然必须在项目的构建路径中添加JRE系统库(1.8.0 v161)。

The actual problem is: Every time I restart Eclipse, the red "x" are back and I have to add Java again. 实际的问题是:每次我重新启动Eclipse时,红色的“ x”又回来了,我必须再次添加Java。

How can I keep Eclipse from forgetting the library? 如何防止Eclipse忘记库?

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>

Neither java.awt nor javax.swing are part of the Android API (because Android uses its own UI toolkit). java.awtjavax.swing都不是Android API的一部分(因为Android使用自己的UI工具包)。 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. 您可以通过“ 添加外部JAR ...”将JRE / JDK的lib/rt.jar 添加到Java Build Path,但这是一个肮脏的把戏。

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

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