简体   繁体   English

eclipse / android / java-无法从libs中的jar文件引用类

[英]eclipse / android / java - cant reference class from jar file in libs

OK, so I made a jar file, using the eclipse export feature, on one of my projects, let's call it X. OK,所以我使用了eclipse导出功能在我的一个项目中创建了一个jar文件,我们将其命名为X。

So X.jar has a single class in it, M.class. 因此X.jar中只有一个类M.class。

I took this jar and put it into the libs/ folder of another project. 我把这个罐子放到另一个项目的libs /文件夹中。

When I do 当我做

M m = new M()

it tells me it can't find M, and offers to import it from the package it's in. When I accept that import, it tells me the import cannot be found. 它告诉我找不到M,并提供从它所在的包中导入它的信息。当我接受该导入时,它告诉我找不到导入。

Now, what's confusing (or at least frustrating) is that if I export the jar with M.java instead of M.class, it works - but I need the jar to not be recompiled in the new project, hence why I was hoping to use the class file and not the source. 现在,令人困惑(或至少令人沮丧)的是,如果我使用M.java而不是M.class导出jar,它可以工作-但我需要不将该jar重新编译到新项目中,因此为什么我希望使用类文件而不是源文件。

Instead of placing the jar file in the lib folder, try adding it to the build path. 与其将jar文件放在lib文件夹中,不如尝试将其添加到构建路径中。

In eclipse: 在日食中:

right click on the project -> Build Path -> Configure Build path... -> Add External JARS

In IntelliJ: 在IntelliJ中:

Ctrl+Alt+Shift+S -> Libraries -> new(Plus Sign)

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

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