Tag: intellij idea

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> […]

在java中不能追加excel文件内容获取堆转储错误

我正在使用apache-poi-3.16.我试图多次写入一个文件而不是一个镜头,但在intelliJ的想法中得到了heal dump error。请查找下面的代码以供参考, public class SampleExcelGeneration { public static void main(String[] args) { SampleExcelGeneration excelGeneration = new SampleExcelGeneration(); excelGeneration.writeFile(); excelGeneration.writeFile(); excelGeneration.writeFile(); excelGeneration.writeFile(); excelGeneration.writeFile(); } private void writeFile () { try { final File file = new File("test.xlsx"); XSSFWorkbook wb; XSSFSheet sheet; if(file.exists()) { wb = new XSSFWorkbook(file.getAbsolutePath()); sheet = wb.getSheetAt(0); } else { wb = […]

在Intellij中为JAVA导入Apache POI

我正在尝试使用Java电子表格,我读了Apache POI看起来像关于我的担忧的最佳解决scheme… 我从http://poi.apache.org/download.html下载了POI 3.11的最新稳定版本 之后,我尝试用两种方法将其添加到我的Intellij项目中: 文件 – 项目结构 – 模块 – 依赖关系 – 添加 – 兴趣点 文件 – 项目结构 – 图书馆 – 添加 – 兴趣点 之后,我尝试导入文档中指定的内容: import org.apache.poi 但它不工作,我想这是因为我没有正确地添加库。