1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.codehaus.mojo.jaxws;
19
20 import java.io.File;
21 import java.net.MalformedURLException;
22 import java.net.URL;
23 import java.net.URLClassLoader;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.maven.artifact.Artifact;
28 import org.apache.maven.artifact.DependencyResolutionRequiredException;
29 import org.apache.maven.plugin.AbstractMojo;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.project.MavenProject;
32
33
34
35
36
37
38
39
40 abstract class AbstractJaxwsMojo extends AbstractMojo {
41
42
43
44
45
46 protected MavenProject project;
47
48
49
50
51
52
53 protected boolean verbose;
54
55
56
57
58
59
60 protected boolean keep;
61
62
63
64
65
66
67 protected boolean extension;
68
69
70
71
72
73
74
75
76 private Map pluginArtifactMap;
77
78
79
80
81 protected abstract File getDestDir();
82
83
84
85
86
87
88 protected String initClassLoader( ClassLoader parent )
89 throws MojoExecutionException
90 {
91
92 try
93 {
94 List classpathFiles = project.getCompileClasspathElements();
95
96 URL[] urls = new URL[classpathFiles.size() + 3];
97
98 StringBuffer classPath = new StringBuffer();
99
100 for ( int i = 0; i < classpathFiles.size(); ++i )
101 {
102 getLog().debug( (String) classpathFiles.get( i ) );
103 urls[i] = new File( (String) classpathFiles.get( i ) ).toURL();
104 classPath.append( (String) classpathFiles.get( i ) );
105 classPath.append( File.pathSeparatorChar );
106 }
107
108
109 urls[classpathFiles.size()] = new File( project.getBuild().getOutputDirectory() ).toURL();
110
111 Artifact jaxwsToolsArtifact = (Artifact) pluginArtifactMap.get( "com.sun.xml.ws:jaxws-tools" );
112 urls[classpathFiles.size() + 1] = jaxwsToolsArtifact.getFile().toURL();
113
114 File toolsJar = new File( System.getProperty( "java.home"), "../lib/tools.jar" );
115 if ( ! toolsJar.exists() )
116 {
117
118 toolsJar = new File( System.getProperty( "java.home"), "lib/tools.jar" );
119 }
120 urls[classpathFiles.size() + 2] = toolsJar.toURL();
121
122 URLClassLoader cl = new URLClassLoader( urls, parent );
123
124
125 Thread.currentThread().setContextClassLoader( cl );
126
127 System.setProperty( "java.class.path", classPath.toString() );
128
129 String sysCp = System.getProperty( "java.class.path" );
130
131 return sysCp;
132 }
133 catch ( MalformedURLException e )
134 {
135 throw new MojoExecutionException( e.getMessage(), e );
136 }
137 catch ( DependencyResolutionRequiredException e )
138 {
139 throw new MojoExecutionException( e.getMessage(), e );
140 }
141
142 }
143 }