Tag: jar

Java Maven在Jar中打包Excel文件

我在资源文件夹中有几个资源文件(excel文件),我想打包到我的jar文件中,这样当我组装我的项目时,它会将excel文件打包到jar文件中,用户不必提供额外的文件当运行jar子。 我的项目结构是这样的: /MyApp |-src |—main |—–java |——-app |———Main.java |—–resources |——-Something.xlsx 这是我的maven pom: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>groupId</groupId> <artifactId>artifactId</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.15</version> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>sample.Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> […]

把一个xls文件放入一个jar文件中

我有一个xls电子表格,我使用metaModel查询,我想保留在jar中的xls文件,因为它不会被更新。 用于创build数据上下文的方法不允许inputstream,我尝试使用此代码: DataContext dataContext = DataContextFactory.createExcelDataContext(getClass().getResourceAsStream("database.xls")); 不幸的是,这不起作用,因为createExcelDataContext方法不会将inputstream作为参数。 有没有办法将文件保存在jar中? 看起来最简单的方法就是导出到csv,因为这很容易完成。

poi-ooxml-schemas-3.14 JAR中缺lessSTSheetViewType类

目前我正试图实现这个问题的答案给出的代码: CTSheetView view = sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0); view.setView(STSheetViewType.PAGE_LAYOUT); 但poi-ooxml-schemas(版本3.14)JAR文件不包含类STSheetViewType。 我深入研究了poi-ooxml-schemas JAR文件(使用7ZIP),发现类文件STSheetViewType $ Enum.class存在于path中: org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetViewType $ Enum.class 但是(如果我没有错)“$”表示一个内部/嵌套类,这意味着STSheetViewType枚举被封装在另一个类。 我在这里检查了旧版本poi-ooxml-schemas(版本1.1)中STSheetViewType类的文档,发现类STSheetViewType包含一个内部Enum STSheetViewType.Enum。 这也似乎证实了我从Eclipse中收到的错误。 使用上面显示的代码时出现这些错误: “STSheetViewType不能parsing为variables” “typesorg.openxmlformats.schemas.spreadsheet.xml.x2006.main.STSheetViewType无法parsing,它是从所需的.class文件间接引用的” 这进一步使我相信STSheetViewType.Enum缺less其父STSheetViewType类文件。 但为什么? 我检查了poi-ooxml-schemas-3.14的新版本的文档,发现更新日志中没有提到STSheetViewType。 我已经下载了POI的二进制压缩文件几次,以确保我的下载没有错误,我甚至下载了源代码,并尝试构buildJAR,但每次都丢失类文件。 我发现类似STSheetViewType看起来相同的function是在另一个Jar文件中,但我似乎无法正确导入类。 这样的事情甚至可能吗? 或者必须将类文件与poi-ooxml-schemas-3.14 JAR文件一起使用? 最终,我想了解如何使上面的代码与当前版本的poi-ooxml-schemas-3.14 JAR兼容。 任何信息或见解,将不胜感激。

即使将jar文件包含在classpath中,也无法在运行时find类

我正在尝试使用apache poi api 。 我已经下载了jar库。 这是我写的代码。 该文件的名称是Main.java 。 /* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main […]

在执行可运行jar文件(java代码)时,我得到java.lang.reflect.InvocationTargetException

作为我的一个项目任务的一部分,我需要从Excel中读取一些数据,通过Sikuli使用这些数据处理应用程序,然后将结果写回Excel。 它在Eclipse中工作正常。 但是,当我把Java文件导出到一个Runnable jar文件时,我得到一个错误(堆栈跟踪在这篇文章的底部)。 谁能帮我解决这个问题吗? 请在下面find我的Java代码: package Auto_a; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.sikuli.script.FindFailed; import org.sikuli.script.Key; import org.sikuli.script.Screen; public class Calculator_b { public static String[] temp1 = new String[50]; public static String temp,temp2; public static String var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12; public static […]

包括一个Excel文件和调用一次打包成一个jar子

我开发了一个ExcelReader / Writer程序,可以在其他计算机上运行。 在这个程序中,它接收一个excel.xls的硬数据,读取并以格式化的方式将其写入excel.xlsx文件,然后将其保存在“ CoC-Forms ”目录中。 为了减less运行我的程序的步骤,我已经在项目中包含了空的.xlsx文件。 但是,将其导出到可执行jar(在其他计算机上运行)时,似乎无法访问此空格式。 我知道这可能是一个非常简单的答案,但是我被困在一个完整的工作日,并且完全停止了我的进步。 这是我的环境的片段。 左边是我在Intellij中的Project目录(CoC.xlsx是空的表单),右边的高亮部分是我尝试访问文件的位置以及错误发生的位置。 JOptionPane.showMessageDialog(null,"About to look for CoC"); //fileFrom = new File(s + "/out/production/XML Reader/CoC.xlsx"); //fileFrom = new File("/XML Reader/out/production/XML Reader/CoC.xlsx"); //fileFrom = new File("CoC.xlsx"); //fileFrom = new File(ExcelWriter.class.getResource("CoC.xlsx").getPath()); CodeSource src = ExcelWriter.class.getProtectionDomain().getCodeSource(); /*if (src != null) { URL url = new URL(src.getLocation(), "CoC.xlsx"); fileFrom = new […]

用于Java包的jar工具org.apache.poi.hssf.usermodel。*

我正在使用Spring / Hibernate(使用NetBeans 6.9.1)。 我需要将Excel工作表导入Oracle数据库(10g)。 我曾经访问过一些文章和教程,其中我find了相应的代码,但是包含此function所需的Java包org.apache.poi.hssf.usermodel.*的Jar实用程序尚未在互联网上find的这些教程中提到的任何一个。 所以只有一个问题 从哪里可以下载这个包含这个包org.apache.poi.hssf.usermodel.* jar工具? 这个包包含了Java类 org.apache.poi.hssf.usermodel.HSSFSheet; org.apache.poi.hssf.usermodel.HSSFWorkbook; org.apache.poi.hssf.usermodel.HSSFRow; org.apache.poi.hssf.usermodel.HSSFCell;