2

I had use zip4j lib net.lingala.zip4j for build winrar project javafx but had this error

Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:/Program Files/Java/jdk-11.0.14/bin/java.exe'' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:414)
    at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:52)

I had add lib to dependencies to gradle

implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '2.9.0'

In file module-info.java I had added

module com.example.compresszip {
    requires javafx.controls;
    requires javafx.fxml;
    requires zip4j;

    opens com.example.compresszip to javafx.fxml;
    exports com.example.compresszip;
}

In main class i had added

import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.CompressionMethod;

public class ZipDemo {
    public static final String OUTPUT_ZIP_FILE = "D:\\demozip\\cms.zip";
    public static final String SOURCE_FOLDER = "D:\\demozip\\cms";
    public static final String PASSWORD = "12345";

    public static void main(String[] args){
        try {

            System.out.println("dvadvav");
            ZipFile z = new ZipFile(OUTPUT_ZIP_FILE);
            z.addFile(new File("D:\\demozip\\cms\\build.gradle"));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
jewelsea
  • 150,031
  • 14
  • 366
  • 406
quangdang
  • 116
  • 7

1 Answers1

1

In this case I don't use gradle but Using maven it work well

  • I think there is a reason this works when using Maven rather than Gradle. I think, by default, Maven will put all the jars on the module path, in which case zip4j can be recognized as an "automatic module". Gradle only puts well-defined modules on the module path by default (e.g. ones that have a module-info.java defined for them, or perhaps an "automatic module" meta-inf in the manifest). The version of zip4j used here (as far as I can tell), is unaware of the Java module system, so you would need additional work to make it work with Gradle, but not Maven. – jewelsea Apr 27 '22 at 23:44
  • There may also be other issues going on with the build for this project that cause the specific error in the question, but I think the above comment applies to trying to use automatic modules from Gradle in general (and also specifically for the zip4j library). – jewelsea Apr 27 '22 at 23:51