Jar文件是否需要.class文件才能执行

时间:2020-08-16 18:33:09

标签: java jar executable

当前,我正在尝试以编程方式生成可执行的JAR文件。

我一直在使用该线程(How to use JarOutputStream to create a JAR file?)来生成JAR文件,但到目前为止,它已经包含了我的测试项目的本机.java文件。

现在我想知道,如果只用本机类填充它,是否有可能运行JAR文件 还是我必须(以某种方式)将它们编译成.class文件,然后才能生成JAR文件。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

Jar存档是具有特殊文件夹结构的zip存档。该结构应具有* .class文件+资源文件。 可选地,源也可以在此存档中,但是不建议这样做(最好为源提供单独的jar文件)。

可执行jar文件是普通jar文件+ Manifest.MF,其中MainClass选项存在,并带有PermissionError Traceback (most recent call last) ~\Documents\Anaconda\anaconda better\lib\site-packages\xlsxwriter\workbook.py in close(self) 315 try: --> 316 self._store_workbook() 317 except IOError as e: ~\Documents\Anaconda\anaconda better\lib\site-packages\xlsxwriter\workbook.py in _store_workbook(self) 631 except IOError as e: --> 632 raise e 633 ~\Documents\Anaconda\anaconda better\lib\site-packages\xlsxwriter\workbook.py in _store_workbook(self) 628 try: --> 629 xlsx_file = ZipFile(self.filename, "w", compression=ZIP_DEFLATED, 630 allowZip64=self.allow_zip64) ~\Documents\Anaconda\anaconda better\lib\zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps) 1249 try: -> 1250 self.fp = io.open(file, filemode) 1251 except OSError: PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Donnie\\Desktop\\Python_Practice.xlsx' During handling of the above exception, another exception occurred: FileCreateError Traceback (most recent call last) <ipython-input-218-c060b0b7e2f2> in <module> 15 AAPL=pd.DataFrame(data, columns = ['High','Adj Close']) 16 ---> 17 AAPL.to_excel(r'C:\Users\Donnie\Desktop\Python_Practice.xlsx',sheet_name = 'Python',index = False,header = True) 18 19 ~\Documents\Anaconda\anaconda better\lib\site-packages\pandas\core\generic.py in to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep, verbose, freeze_panes) 2173 inf_rep=inf_rep, 2174 ) -> 2175 formatter.write( 2176 excel_writer, 2177 sheet_name=sheet_name, ~\Documents\Anaconda\anaconda better\lib\site-packages\pandas\io\formats\excel.py in write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine) 736 ) 737 if need_save: --> 738 writer.save() ~\Documents\Anaconda\anaconda better\lib\site-packages\pandas\io\excel\_xlsxwriter.py in save(self) 193 """ 194 --> 195 return self.book.close() 196 197 def write_cells( ~\Documents\Anaconda\anaconda better\lib\site-packages\xlsxwriter\workbook.py in close(self) 316 self._store_workbook() 317 except IOError as e: --> 318 raise FileCreateError(e) 319 except LargeZipFile as e: 320 raise FileSizeError("Filesize would require ZIP64 extensions. " FileCreateError: [Errno 13] Permission denied: 'C:\\Users\\Donnie\\Desktop\\Python_Practice.xlsx' 方法到主类的完整路径(从jar文件的根目录开始)。