Activiti工作流zip方式部署失败问题

Activiti工作流zip方式部署失败问题

因最近工作需要,故学习activiti工作流,过程有点曲折,待整理完成后,将个人学习过程分享一下.
本次记录的问题,是在学习过程中,遇到一个有意思的问题,给大家避雷.

参考资料: https://www.caogenjava.com/detail/91.html

0 问题起因

Activiti工作流常用的部署方式有三种:

  • classpath 直接加载bpmn和png文件
  • 使用addInputStream流加载bpmn和png文件
  • 使用addZipInputStream流加载zip文件

前面两种方式,在使用过程中,没有问题.
第三种方法,使用后,只会在act_re_deployment(部署对象表)添加记录,其他表则没有记录,如act_ge_bytearray(资源文件表)等.

1 分析过程

1 运行也没报错,通过debug发现, entry对象为null.
在这里插入图片描述
2 怀疑加载zip文件到创建zipInputStream 有问题

		//加载zip文件
       InputStream inputStream = this.getClass()
                .getClassLoader()
                .getResourceAsStream("bpmn/bpmn.zip");
		//创建zipInputStream 流
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);

3 经过debug,发现过程中都不报错,且不为null,但是entry对象仍然为null.

4 查询资料后,说使用org.apache.ant可以解决.
0 导入jar包

<dependency>
  <groupId>org.apache.ant</groupId>
  <artifactId>ant</artifactId>
  <version>1.9.6</version>
</dependency>

1 使用测试方法

    @Test
    public void test2() throws IOException {
    
    
        ZipFile zip = new ZipFile(new File("D:/2.code/study/202101/activiti-domo/src/main/resources/bpmn/bpmn.zip"),"GBK");
        Enumeration<ZipEntry> enumeration =  zip.getEntries();
        while (enumeration.hasMoreElements()) {
    
    
            org.apache.tools.zip.ZipEntry zipEntry = enumeration.nextElement();
            System.out.println(zipEntry.getName());
        }
    }

2 结果报错: java.util.zip.ZipException: archive is not a ZIP archive
3 翻译错误: 该文件不是zip文件

5 重点来了,我提供的文件明明是zip文件,为啥程序说不是.

6 在网上查询后,发现有问题,我使用压缩工具是rar,压缩完后,直接修改了后缀为.zip,和直接压缩成.zip的文件是不一样的.
在这里插入图片描述

2 解决方法

修改压缩方式,直接压缩为.zip, 程序恢复了正常.

果然,眼见为虚!!!

猜你喜欢

转载自blog.csdn.net/ABestRookie/article/details/112425657