简体   繁体   English

使用java源码包

[英]using java source package

I am fairly new to java having come from a VS2010 background. 我对来自VS2010背景的Java相当陌生。 Currently working on an android app that uses a couple of 3rd party packages of the web - one of which I would like to use the source package for debugging purposes. 目前正在使用一个使用两个Web第三方包的Android应用程序-我想使用其中的一个源包进行调试。 I cannot seem to get this to work - I initally copied and pasted source jar files to lib directory and had to change import statements but compile still fails with "package does not exist" and "cannot find symbol class". 我似乎无法正常工作-我最初将源jar文件复制并粘贴到lib目录,不得不更改import语句,但是编译仍然失败,并显示“包不存在”和“找不到符号类”。 Where do source files need to go within the project? 源文件需要放在项目中的什么位置? (Using IntelliJ 11) (使用IntelliJ 11)

Thanks in advance. 提前致谢。

Typically a source JAR would be used in addition to the normal, binary JAR which contains the classes. 通常,除了包含这些类的常规二进制JAR 之外,还将使用源JAR。 The latter is still needed to actually load class definitions. 实际加载类定义仍需要后者。 If you removed it, and replaced it with a JAR (which is basically just a Zip file) full of *.java source files, then your application won't be able to find and load the library classes any more. 如果删除了它,并用充满*.java源文件的JAR(基本上只是一个Zip文件)替换了它,那么您的应用程序将无法再查找和加载库类。

So to actually answer your question - the source JAR can live anywhere , as you have to tell IntelliJ where it is. 因此,要真正回答您的问题-源JAR可以存在于任何地方 ,因为您必须告诉IntelliJ它在哪里。 Open up the Project Structure window, then on the Dependencies tab find the reference to the binary library in question (you still have it in your project, right?). 打开“项目结构”窗口,然后在“依赖关系”选项卡上找到有问题的二进制库的引用(您在项目中仍然有它,对吗?)。 Then click on the pencil icon to edit it, go to Attach Files or Directories, and then select your source JAR. 然后单击铅笔图标进行编辑,转到“附加文件或目录”,然后选择源JAR。

IntelliJ will recognise the JAR as full of sources, and will use these to display the code for the classes within the library, as you desire. IntelliJ会将JAR识别为完整的源,并根据需要使用这些源来显示库中类的代码。

第三方jar应当配置为模块依赖项 ,您可以将源jar附加到库以逐步浏览代码或查看文档。

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

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