简体   繁体   English

向现有的JAR文件中添加新类(包含源代码)

[英]Add a new class to an existing JAR File(which contains source code)

I'll try to illustrate the problem as simple as I can. 我将尝试尽可能简单地说明问题。

I have a JAR file, which I extracted using Winrar. 我有一个使用Winrar提取的JAR文件。 (The jar file contains an open source android library). (jar文件包含一个开放源代码的android库)。
I want to modify this JAR file by adding a new class to the library. 我想通过向库中添加新类来修改此JAR文件。

So here are my steps: 所以这是我的步骤:
First, I created a class using Eclipse and set the package name same as the android's library package name. 首先,我使用Eclipse创建了一个类,并将包名称设置为与android库的包名称相同。
Second, I copied this java File to the folder of the other java files in the library. 其次,我将此Java文件复制到库中其他Java文件的文件夹中。
Third, I tried to compile the JAVA file via the CMD using javac. 第三,我尝试使用javac通过CMD编译JAVA文件。

The path of the new java file and the other .JAVA and .CLASS files of the library is: C:\\com\\example\\core\\ 新的Java文件以及该库的其他.JAVA和.CLASS文件的路径为: C:\\com\\example\\core\\
The name of the new java file would be: "MyNewClass.java" 新的Java文件的名称为: "MyNewClass.java"
The command I run via the CMD is: javac C:\\com\\example\\core\\MyNewClass.java 我通过CMD运行的命令是: javac C:\\com\\example\\core\\MyNewClass.java

But, during the compilation I get many errors saying: Cannot find symbols. 但是,在编译过程中,我遇到许多错误:“找不到符号”。

I've been looking up for a solution of this problem but couldn't figure how to solve it and make the new JAR File having another class that I created seperately. 我一直在寻找解决此问题的方法,但无法解决如何解决这个问题,并使新的JAR文件具有我单独创建的另一个类。

What am I missing? 我想念什么?

As per earlier comments: 根据之前的评论:

Rather than trying to modify the JAR, you can get access to the full source code of the Universal Image Loader library by cloning the repository using git or hitting "Download ZIP" on the righthand side of the page you linked. 无需尝试修改JAR,您可以通过使用git克隆存储库或单击链接页面右侧的“下载ZIP”来访问Universal Image Loader库的完整源代码。

Once you have the source, import the library in your IDE. 获得源代码后,将库导入到IDE中。 From there on you'll be able to build the whole thing from scratch, make any adjustments/modifications you like, etc. 从那里开始,您将能够从头开始构建整个内容,进行所需的任何调整/修改,等等。

Your classpath might be wrong or there might be some mistake in package name. 您的类路径可能错误,或者程序包名称可能有误。

When a Java program is being compiled the compiler it creates a list of all the identifiers in use. 编译Java程序时,编译器会创建一个所有使用中标识符的列表。 If it can't find what an identifier refers to it cannot complete the compilation. 如果找不到标识符所指的内容,则无法完成编译。 This is what the cannot find symbol error message is saying, it doesn't have enough information to piece together what the Java code wants to execute. 这就是找不到符号错误消息的意思,它没有足够的信息来拼凑Java代码想要执行的内容。

Try: 尝试:

javac -cp com/* C:\com\example\core\MyNewClass.java

That should make the compiler aware of all the other classes under com/... 那应该使编译器知道com /下的所有其他类。

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

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