Example usage for org.springframework.boot.loader.tools Repackager repackage

List of usage examples for org.springframework.boot.loader.tools Repackager repackage

Introduction

In this page you can find the example usage for org.springframework.boot.loader.tools Repackager repackage.

Prototype

public void repackage(File destination, Libraries libraries, LaunchScript launchScript) throws IOException 

Source Link

Document

Repackage to the given destination so that it can be launched using ' java -jar '.

Usage

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void addLauncherScript() throws Exception {
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File source = this.testJarFile.getFile();
    File dest = this.temporaryFolder.newFile("dest.jar");
    Repackager repackager = new Repackager(source);
    LaunchScript script = new MockLauncherScript("ABC");
    repackager.repackage(dest, NO_LIBRARIES, script);
    byte[] bytes = FileCopyUtils.copyToByteArray(dest);
    assertThat(new String(bytes)).startsWith("ABC");
    assertThat(hasLauncherClasses(source)).isFalse();
    assertThat(hasLauncherClasses(dest)).isTrue();
    try {//from   w ww  .  j  a  va2s .c o  m
        assertThat(Files.getPosixFilePermissions(dest.toPath())).contains(PosixFilePermission.OWNER_EXECUTE);
    } catch (UnsupportedOperationException ex) {
        // Probably running the test on Windows
    }
}