从 Jar 重新编译 Java 类 [英] Re-compile a Java Class from Jar

查看:21
本文介绍了从 Jar 重新编译 Java 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可执行 jar,其中有一个类文件的值错误.我向作者索取了该文件并更正了该值.

现在我要编译它并将编译后的类文件添加到jar中并运行它.

对于 jar 文件中的自定义对象的引用,我收到多个找不到符号"错误并不奇怪.

我试图通过像这样引用类路径中的 jar 文件来编译文件

<前>C:/> javac file.java -classpath C:/folder/where/jar/is

但这似乎不起作用...我遇到了与刚刚执行相同的错误

<前>C:/> javac文件.java

有没有办法编译这个单独的类,以某种方式引用 jar 中的其他文件?

谢谢.

<小时>

我在遵循以下一些建议时遇到的错误:

<前>javac -classpath C:/jar/location.jar File.javaFile.java:226: 找不到符号符号:类东西位置:com.shared.stuffers 类东西 s1 = 新东西();^

在 Jar 中找到了 Stuff 类,但是 javac 程序看不到...我感觉我做错了什么但不知道在哪里?谢谢.

解决方案

你会想要像这样编译你的文件:

javac -classpath C:folderwherejaris	he_jar_file.jar file.java

根据 javac 使用说明:

C:Console2>javac -help用法:javac <源文件>

I have an executable jar that has one class file with a wrong value. I requested that file from the author and corrected the value.

Now I want to compile it and add the compiled class file into the jar and run it.

Not surprisingly I get multiple "cannot find symbol" errors for references of custom object that were in the jar file.

I tried to compile the file by referencing the jar file in the classpath like so

C:/> javac  file.java  -classpath C:/folder/where/jar/is

but this doesnt seem to work... I get the same errors as if just doing

C:/> javac file.java

Is there a way to compile this individual class somehow referencing the other files in the jar?

Thanks.


Errors I am getting while following some of the suggestions below here:

javac -classpath C:/jar/location.jar File.java

File.java:226: cannot find symbol
symbol  : class Stuff
location: class com.shared.stuffers
                              Stuff s1 = new Stuff();
                                             ^

Stuff class is found in the Jar, but can not be seen by the javac program... I feel like I am doing something wrong but not sure where? Thanks.

解决方案

You will want to compile your file like so:

javac -classpath C:folderwherejaris	he_jar_file.jar file.java

per the javac usage instructions:

C:Console2>javac -help
Usage: javac <options> <source files>

这篇关于从 Jar 重新编译 Java 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆