[英]How to use Jar file As a Java project in Eclipse
I have a jar file of an existing project. 我有一个现有项目的jar文件。 I want to write Junit test cases for each class in that project. 我想为该项目中的每个类编写Junit测试用例。 To do that, I want to import that jar file as a java project in Eclipse so I can start new development of the same code. 要做到这一点,我想导入jar文件在Eclipse Java项目,所以我可以开始相同的代码的新的发展。 Is it possible to import a .jar
file the same way we did for a .war
file, and start developing the web project? 是否有可能导入.jar
文件,我们做了同样的方式.war
文件,并开始开发web项目? If so, how? 如果是这样,怎么办?
A .jar file is just a .zip file containing all the class files of your java project. .jar文件只是一个.zip文件,其中包含Java项目的所有类文件。 If the source files are included in the .jar file, you can unzip it and add them in eclipse. 如果源文件包含在.jar文件中,则可以将其解压缩并将其添加到eclipse中。 If they aren't, then you can't do what you want to do. 如果不是,那么您将无法做您想做的事。
If you have source files in your jar ie .java
files along with your .class
files, then rename your jar to zip and unzip the files. 如果您的jar中有源文件,即.java
文件和.class
文件,请重命名jar以压缩和解压缩文件。 These java files can now be manually copied under src
folder in eclipse. 这些Java文件现在可以在eclipse中的src
文件夹下手动复制。
Once your modifications are done, the new jar with your modifications can be created like this -> Right click on project ->export->Java->Jar
option in eclipse. 修改完成后,可以按以下方式创建带有修改的新Right click on project ->export->Java->Jar
在Eclipse中Right click on project ->export->Java->Jar
选项。 Or you can use ANT/Maven or similar build tool. 或者,您可以使用ANT / Maven或类似的构建工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.