Skip to content

Commit 6673d8e

Browse files
committed
Polish "Allow loader.path to refer to nested jars"
Closes gh-8334 Closes gh-8465
1 parent 3701cce commit 6673d8e

File tree

8 files changed

+152
-23
lines changed

8 files changed

+152
-23
lines changed

spring-boot-docs/src/main/asciidoc/appendix-executable-jar-format.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ files in directories (as opposed to explicitly on the classpath). In the case of
147147
you just add extra jars in those locations if you want more. The `PropertiesLauncher`
148148
looks in `BOOT-INF/lib/` in your application archive by default, but you can add
149149
additional locations by setting an environment variable `LOADER_PATH` or `loader.path`
150-
in `loader.properties` (comma-separated list of directories or archives).
150+
in `loader.properties` (comma-separated list of directories, archives, or directories
151+
within archives).
151152

152153

153154

@@ -280,7 +281,8 @@ the `Main-Class` attribute and leave out `Start-Class`.
280281
* `loader.home` is only the directory location of an additional properties file
281282
(overriding the default) as long as `loader.config.location` is not specified.
282283
* `loader.path` can contain directories (scanned recursively for jar and zip files),
283-
archive paths, or wildcard patterns (for the default JVM behavior).
284+
archive paths, a directory within an archive that is scanned for jar files (for
285+
example, `dependencies.jar!/lib`), or wildcard patterns (for the default JVM behavior).
284286
* `loader.path` (if empty) defaults to `BOOT-INF/lib` (meaning a local directory or a
285287
nested one if running from an archive). Because of this `PropertiesLauncher` behaves the
286288
same as `JarLauncher` when no additional configuration is provided.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
loader.path=jar:file:../executable-props/target/executable-props-0.0.1.BUILD-SNAPSHOT-full.jar/!BOOT-INF/lib
1+
loader.path=jar:file:target/executable-props-lib-0.0.1.BUILD-SNAPSHOT-dependencies.jar/!BOOT-INF/lib

spring-boot-tools/spring-boot-loader/src/it/executable-props-lib/pom.xml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,56 @@
3939
<type>jar</type>
4040
</artifactItem>
4141
</artifactItems>
42-
<outputDirectory>${project.build.directory}/assembly</outputDirectory>
42+
<outputDirectory>${project.build.directory}/app-assembly</outputDirectory>
43+
</configuration>
44+
</execution>
45+
<execution>
46+
<id>copy</id>
47+
<phase>prepare-package</phase>
48+
<goals>
49+
<goal>copy-dependencies</goal>
50+
</goals>
51+
<configuration>
52+
<outputDirectory>${project.build.directory}/dependencies-assembly/BOOT-INF/lib</outputDirectory>
4353
</configuration>
4454
</execution>
4555
</executions>
4656
</plugin>
4757
<plugin>
4858
<artifactId>maven-assembly-plugin</artifactId>
4959
<version>2.4</version>
50-
<configuration>
51-
<descriptors>
52-
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
53-
</descriptors>
54-
<archive>
55-
<manifest>
56-
<mainClass>org.springframework.boot.loader.PropertiesLauncher</mainClass>
57-
</manifest>
58-
<manifestEntries>
59-
<Start-Class>org.springframework.boot.load.it.props.EmbeddedJarStarter</Start-Class>
60-
</manifestEntries>
61-
</archive>
62-
</configuration>
6360
<executions>
6461
<execution>
65-
<id>jar-with-dependencies</id>
62+
<id>app</id>
6663
<phase>package</phase>
6764
<goals>
6865
<goal>single</goal>
6966
</goals>
67+
<configuration>
68+
<descriptors>
69+
<descriptor>src/main/assembly/app.xml</descriptor>
70+
</descriptors>
71+
<archive>
72+
<manifest>
73+
<mainClass>org.springframework.boot.loader.PropertiesLauncher</mainClass>
74+
</manifest>
75+
<manifestEntries>
76+
<Start-Class>org.springframework.boot.launcher.it.props.EmbeddedJarStarter</Start-Class>
77+
</manifestEntries>
78+
</archive>
79+
</configuration>
80+
</execution>
81+
<execution>
82+
<id>depedendencies</id>
83+
<phase>package</phase>
84+
<goals>
85+
<goal>single</goal>
86+
</goals>
87+
<configuration>
88+
<descriptors>
89+
<descriptor>src/main/assembly/dependencies.xml</descriptor>
90+
</descriptors>
91+
</configuration>
7092
</execution>
7193
</executions>
7294
</plugin>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
6-
<id>full</id>
6+
<id>app</id>
77
<formats>
88
<format>jar</format>
99
</formats>
@@ -20,7 +20,7 @@
2020
</dependencySets>
2121
<fileSets>
2222
<fileSet>
23-
<directory>${project.build.directory}/assembly</directory>
23+
<directory>${project.build.directory}/app-assembly</directory>
2424
<outputDirectory>/</outputDirectory>
2525
</fileSet>
2626
</fileSets>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<assembly
3+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
6+
<id>dependencies</id>
7+
<formats>
8+
<format>jar</format>
9+
</formats>
10+
<includeBaseDirectory>false</includeBaseDirectory>
11+
<fileSets>
12+
<fileSet>
13+
<directory>${project.build.directory}/dependencies-assembly</directory>
14+
<outputDirectory>/</outputDirectory>
15+
</fileSet>
16+
</fileSets>
17+
</assembly>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.launcher.it.props;
18+
19+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
20+
21+
/**
22+
* Main class to start the embedded server.
23+
*
24+
* @author Dave Syer
25+
*/
26+
public final class EmbeddedJarStarter {
27+
28+
public static void main(String[] args) throws Exception {
29+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfiguration.class);
30+
context.getBean(SpringConfiguration.class).run(args);
31+
context.close();
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.launcher.it.props;
18+
19+
import java.io.IOException;
20+
import java.util.Properties;
21+
22+
import javax.annotation.PostConstruct;
23+
24+
import org.springframework.context.annotation.ComponentScan;
25+
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.core.io.ClassPathResource;
27+
28+
/**
29+
* Spring configuration.
30+
*
31+
* @author Dave Syer
32+
*/
33+
@Configuration
34+
@ComponentScan
35+
public class SpringConfiguration {
36+
37+
private String message = "Jar";
38+
39+
@PostConstruct
40+
public void init() throws IOException {
41+
Properties props = new Properties();
42+
props.load(new ClassPathResource("application.properties").getInputStream());
43+
String value = props.getProperty("message");
44+
if (value!=null) {
45+
this.message = value;
46+
}
47+
48+
}
49+
50+
public void run(String... args) {
51+
System.err.println("Hello Embedded " + this.message + "!");
52+
}
53+
54+
}

spring-boot-tools/spring-boot-loader/src/it/executable-props-lib/verify.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def jarfile = './target/executable-props-lib-0.0.1.BUILD-SNAPSHOT-full.jar'
1+
def jarfile = './target/executable-props-lib-0.0.1.BUILD-SNAPSHOT-app.jar'
22

33
new File("${basedir}/application.properties").delete()
44

@@ -10,8 +10,8 @@ String exec(String command) {
1010

1111
String out = exec("java -jar ${jarfile}")
1212
assert out.contains('Hello Embedded World!'),
13-
'Using -jar my.jar should use the application.properties from the jar\n' + out
13+
'Using -jar my.jar should load dependencies from separate jar and use the application.properties from the jar\n' + out
1414

1515
out = exec("java -cp ${jarfile} org.springframework.boot.loader.PropertiesLauncher")
1616
assert out.contains('Hello Embedded World!'),
17-
'Using -cp my.jar with PropertiesLauncher should use the application.properties from the jar\n' + out
17+
'Using -cp my.jar with PropertiesLauncher should load dependencies from separate jar and use the application.properties from the jar\n' + out

0 commit comments

Comments
 (0)