From 11dd14798670585e0e73ddfae4407426e57c3ccf Mon Sep 17 00:00:00 2001 From: Tzafrir Poupko Date: Mon, 20 Jun 2016 09:17:27 +0300 Subject: [PATCH 1/2] fix path resolution under windows --- .../org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java index e141ef4e..0b34d62c 100644 --- a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java +++ b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java @@ -475,6 +475,8 @@ private WebResource urlToWebResource( URL url, String path ) if ( idx >= 0 ) { String filePath = StringUtils.removeStart( url.getFile().substring( 0, idx ), "file:" ); + // Restore spaces which might be available under windows + filePath = filePath.replaceAll("%20", " "); jarFile = new JarFile( filePath ); From 71c1ac54bde86576b7e3ac72a259705c6b7c9755 Mon Sep 17 00:00:00 2001 From: Tzafrir Poupko Date: Mon, 20 Jun 2016 13:41:38 +0300 Subject: [PATCH 2/2] Use URI instead of URL in urlToWebResource method As suggested by oracle in http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4466485 URL contains %-encoded characters, and it is suggested to use URI to resolve those. --- .../tomcat/maven/plugin/tomcat8/run/RunMojo.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java index 0b34d62c..ac9d79f8 100644 --- a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java +++ b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java @@ -470,13 +470,13 @@ private WebResource urlToWebResource( URL url, String path ) // url.getFile is // file:/Users/olamy/mvn-repo/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar!/org/springframework/web/context/ContextLoaderListener.class - int idx = url.getFile().indexOf( '!' ); + URI uri = new URI(url.getFile()); + String filePath = uri.getPath(); + int idx = filePath.indexOf( '!' ); if ( idx >= 0 ) { - String filePath = StringUtils.removeStart( url.getFile().substring( 0, idx ), "file:" ); - // Restore spaces which might be available under windows - filePath = filePath.replaceAll("%20", " "); + filePath = filePath.substring( 0, idx); jarFile = new JarFile( filePath ); @@ -485,17 +485,21 @@ private WebResource urlToWebResource( URL url, String path ) return new JarResource( this, // getPath(), // filePath, // - url.getPath().substring( 0, idx ), // + "file:"+filePath, // jarEntry, // "", // null ); } else { - return new FileResource( this, webAppPath, new File( url.getFile() ), true ); + return new FileResource( this, webAppPath, new File( filePath ), true ); } } + catch (URISyntaxException e) + { + throw new RuntimeException( e.getMessage(), e ); + } catch ( IOException e ) { throw new RuntimeException( e.getMessage(), e );