简体   繁体   English

如何使用Eclipse将仅包含.java源文件的jar文件编译为包含.class文件的.jar文件

[英]How to compile jar file containing only .java source files into .jar files containing .class files with Eclipse

I have a .zip file that contains a package that holds the different source code files generated from http://www.jsonschema2pojo.org/ . 我有一个.zip文件,其中包含一个软件包,其中包含从http://www.jsonschema2pojo.org/生成的不同源代码文件。

I initially thought I'd be able to add the generated code (contained in .zip file) to my build path directly, however I discovered that I cannot work with .java files in my project, as importing the .zip file into my project shows the package path to be empty. 最初我以为可以将生成的代码(包含在.zip文件中)直接添加到我的构建路径中,但是我发现我无法在项目中使用.java文件,因为将.zip文件导入到我的项目中显示软件包路径为空。

It turns out that I cannot use this .zip file because it is full of .java source files and it has no .class files.. which is why when I attempt to reference the file from my project, it says it can't resolve it to a type. 事实证明,我无法使用此.zip文件,因为它充满了.java源文件并且没有.class文件。这就是为什么当我尝试从项目中引用该文件时,它说无法解析它是一种类型。

I know I can just go through the zip file, create the package and classes and copy/paste the source code, compile all of that, and then reference that in my program. 我知道我可以浏览zip文件,创建包和类,然后复制/粘贴源代码,编译所有代码,然后在程序中引用它们。 However, there has to be an easier way than just doing all of this manually. 但是,必须有一种比手动完成所有操作更简单的方法。

How do I convert a .zip file full of source into a .zip file full of class files directly referenceable from my Eclipse? 如何将包含源代码的.zip文件转换为可直接从Eclipse直接引用的包含类文件的.zip文件?

There is no easy way of achieving what you are looking for, I would recommend to write up a utility program which can take input as ZIP file, iterate the file list, read and create the package folder structure and copy the file to the location. 没有简单的方法可以实现您想要的目标,我建议编写一个实用程序,该实用程序可以将输入作为ZIP文件,迭代文件列表,读取和创建包文件夹结构并将文件复制到该位置。 Before executing this program, you have to create eclipse Java project so that the extracted files can be copied to the workspace. 在执行该程序之前,您必须创建eclipse Java项目,以便可以将提取的文件复制到工作区。 This way it functions properly when program generates the file and then you can extract this package in .jar file. 这样,当程序生成文件时,它便可以正常运行,然后您可以将该包解压缩到.jar文件中。

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

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