From 8fe696944a29f12f5a465a794f0544dc06cce27d Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 6 Jan 2014 17:28:22 +0000 Subject: [PATCH] Delete duplicate logback.xml if running from Maven plugin Fixes gh-143 --- .../java/org/springframework/boot/maven/RunMojo.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java index 73bd8dae8c..323fabf559 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java @@ -87,7 +87,7 @@ public class RunMojo extends AbstractMojo { * the archive. */ @Parameter(defaultValue = "${project.build.outputDirectory}", required = true) - private File classesDirectrory; + private File classesDirectory; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -105,7 +105,7 @@ public class RunMojo extends AbstractMojo { String mainClass = this.mainClass; if (mainClass == null) { try { - mainClass = MainClassFinder.findMainClass(this.classesDirectrory); + mainClass = MainClassFinder.findMainClass(this.classesDirectory); } catch (IOException ex) { throw new MojoExecutionException(ex.getMessage(), ex); @@ -150,11 +150,17 @@ public class RunMojo extends AbstractMojo { for (Resource resource : this.project.getResources()) { urls.add(new File(resource.getDirectory()).toURI().toURL()); } + // Special case: this file causes logback to worry that it has been configured + // twice, so remove it from the target directory... + File logback = new File(this.classesDirectory, "logback.xml"); + if (logback.exists() && logback.canWrite()) { + logback.delete(); + } } } private void addProjectClasses(List urls) throws MalformedURLException { - urls.add(this.classesDirectrory.toURI().toURL()); + urls.add(this.classesDirectory.toURI().toURL()); } private void addDependencies(List urls) throws MalformedURLException {