Add a command to produce a self-contained executable JAR for a CLI app
A new command, jar, has been added to the CLI. The command can be used to create a self-contained executable JAR file from a CLI app. Basic usage is: spring jar <jar-name> <source-files> For example: spring jar my-app.jar *.groovy The resulting jar will contain the classes generated by compiling the source files, all of the application's dependencies, and entries on the application's classpath. By default a CLI application has the current working directory on its classpath. This can be overridden using the --classpath option. Any file that is referenced directly by the classpath is always included in the jar. Any file that is found a result of being contained within a directory that is on the classpath is subject to filtering to determine whether or not it should be included. The default includes are public/**, static/**, resources/**, META-INF/**, *. The default excludes are .*, repository/**, build/**, target/**. To be included in the jar, a file must match one of the includes and none of the excludes. The filters can be overridden using the --include and --exclude options. Closes #241
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.cli.command.jar;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.cli.command.jar.ResourceMatcher.MatchedResource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author awilkinson
|
||||
*/
|
||||
public class ResourceMatcherTests {
|
||||
|
||||
private final ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList(
|
||||
"alpha/**", "bravo/*", "*"), Arrays.asList(".*", "alpha/**/excluded"));
|
||||
|
||||
@Test
|
||||
public void nonExistentRoot() throws IOException {
|
||||
List<MatchedResource> matchedResources = this.resourceMatcher
|
||||
.matchResources(Arrays.asList(new File("does-not-exist")));
|
||||
assertEquals(0, matchedResources.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceMatching() throws IOException {
|
||||
List<MatchedResource> matchedResources = this.resourceMatcher
|
||||
.matchResources(Arrays.asList(new File(
|
||||
"src/test/resources/resource-matcher/one"), new File(
|
||||
"src/test/resources/resource-matcher/two"), new File(
|
||||
"src/test/resources/resource-matcher/three")));
|
||||
System.out.println(matchedResources);
|
||||
List<String> paths = new ArrayList<String>();
|
||||
for (MatchedResource resource : matchedResources) {
|
||||
paths.add(resource.getPath());
|
||||
}
|
||||
|
||||
assertEquals(6, paths.size());
|
||||
assertTrue(paths.containsAll(Arrays.asList("alpha/nested/fileA", "bravo/fileC",
|
||||
"fileD", "bravo/fileE", "fileF", "three")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user