1 18 package org.apache.tools.ant.taskdefs.optional.ejb; 19 20 21 import java.io.File ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Task; 24 import org.apache.tools.ant.taskdefs.Java; 25 import org.apache.tools.ant.types.Path; 26 27 34 public class WLRun extends Task { 35 protected static final String DEFAULT_WL51_POLICY_FILE = "weblogic.policy"; 36 protected static final String DEFAULT_WL60_POLICY_FILE = "lib/weblogic.policy"; 37 protected static final String DEFAULT_PROPERTIES_FILE = "weblogic.properties"; 38 39 44 private Path classpath; 45 46 49 private Path weblogicClasspath; 50 51 private String weblogicMainClass = "weblogic.Server"; 52 53 56 private String additionalArgs = ""; 57 58 61 private String securityPolicy; 62 63 66 private File weblogicSystemHome; 67 68 71 private String weblogicDomainName; 72 73 77 private String weblogicSystemName = "myserver"; 78 79 82 private String weblogicPropertiesFile = null; 83 84 87 private String additionalJvmArgs = ""; 88 89 93 private File beaHome = null; 94 95 98 private String managementUsername = "system"; 99 100 103 private String managementPassword = null; 104 105 108 private String pkPassword = null; 109 110 114 public Path createClasspath() { 115 if (classpath == null) { 116 classpath = new Path(getProject()); 117 } 118 return classpath.createPath(); 119 } 120 121 125 public Path createWLClasspath() { 126 if (weblogicClasspath == null) { 127 weblogicClasspath = new Path(getProject()); 128 } 129 return weblogicClasspath.createPath(); 130 } 131 132 143 public void execute() throws BuildException { 144 if (weblogicSystemHome == null) { 145 throw new BuildException("weblogic home must be set"); 146 } 147 if (!weblogicSystemHome.isDirectory()) { 148 throw new BuildException("weblogic home directory " 149 + weblogicSystemHome.getPath() + " is not valid"); 150 } 151 152 if (beaHome != null) { 153 executeWLS6(); 154 } else { 155 executeWLS(); 156 } 157 } 158 159 private File findSecurityPolicyFile(String defaultSecurityPolicy) { 160 String securityPolicy = this.securityPolicy; 161 if (securityPolicy == null) { 162 securityPolicy = defaultSecurityPolicy; 163 } 164 File securityPolicyFile = new File (weblogicSystemHome, securityPolicy); 165 if (this.securityPolicy != null && !securityPolicyFile.exists()) { 168 securityPolicyFile = getProject().resolveFile(securityPolicy); 169 } 170 if (!securityPolicyFile.exists()) { 172 throw new BuildException("Security policy " + securityPolicy 173 + " was not found."); 174 } 175 return securityPolicyFile; 176 } 177 178 private void executeWLS6() { 179 File securityPolicyFile 180 = findSecurityPolicyFile(DEFAULT_WL60_POLICY_FILE); 181 if (!beaHome.isDirectory()) { 182 throw new BuildException("BEA home " + beaHome.getPath() 183 + " is not valid"); 184 } 185 186 File configFile = new File (weblogicSystemHome, "config/" 187 + weblogicDomainName + "/config.xml"); 188 if (!configFile.exists()) { 189 throw new BuildException("Server config file " + configFile 190 + " not found."); 191 } 192 193 if (managementPassword == null) { 194 throw new BuildException("You must supply a management password " 195 + "to start the server"); 196 } 197 198 Java weblogicServer = new Java(this); 199 weblogicServer.setTaskName(getTaskName()); 200 weblogicServer.setFork(true); 201 weblogicServer.setDir(weblogicSystemHome); 202 weblogicServer.setClassname(weblogicMainClass); 203 204 String jvmArgs = additionalJvmArgs; 205 206 jvmArgs += " -Dweblogic.Domain=" + weblogicDomainName; 207 jvmArgs += " -Dweblogic.Name=" + weblogicSystemName; 208 jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome; 209 210 jvmArgs += " -Dbea.home=" + beaHome; 211 jvmArgs += " -Djava.security.policy==" + securityPolicyFile; 212 213 jvmArgs += " -Dweblogic.management.username=" + managementUsername; 214 jvmArgs += " -Dweblogic.management.password=" + managementPassword; 215 if (pkPassword != null) { 216 jvmArgs += " -Dweblogic.pkpassword=" + pkPassword; 217 } 218 219 220 weblogicServer.createJvmarg().setLine(jvmArgs); 221 weblogicServer.createArg().setLine(additionalArgs); 222 223 if (classpath != null) { 224 weblogicServer.setClasspath(classpath); 225 } 226 227 if (weblogicServer.executeJava() != 0) { 228 throw new BuildException("Execution of weblogic server failed"); 229 } 230 } 231 232 private void executeWLS() { 233 File securityPolicyFile 234 = findSecurityPolicyFile(DEFAULT_WL51_POLICY_FILE); 235 File propertiesFile = null; 236 237 238 if (weblogicPropertiesFile == null) { 239 weblogicPropertiesFile = DEFAULT_PROPERTIES_FILE; 240 } 241 propertiesFile = new File (weblogicSystemHome, weblogicPropertiesFile); 242 if (!propertiesFile.exists()) { 243 propertiesFile = getProject().resolveFile(weblogicPropertiesFile); 245 if (!propertiesFile.exists()) { 246 throw new BuildException("Properties file " 247 + weblogicPropertiesFile 248 + " not found in weblogic home " + weblogicSystemHome 249 + " or as absolute file"); 250 } 251 } 252 253 Java weblogicServer = new Java(this); 254 weblogicServer.setFork(true); 255 weblogicServer.setClassname(weblogicMainClass); 256 257 String jvmArgs = additionalJvmArgs; 258 259 if (weblogicClasspath != null) { 260 jvmArgs += " -Dweblogic.class.path=" + weblogicClasspath; 261 } 262 263 jvmArgs += " -Djava.security.manager -Djava.security.policy==" + securityPolicyFile; 264 jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome; 265 jvmArgs += " -Dweblogic.system.name=" + weblogicSystemName; 266 jvmArgs += " -Dweblogic.system.propertiesFile=" + weblogicPropertiesFile; 267 268 weblogicServer.createJvmarg().setLine(jvmArgs); 269 weblogicServer.createArg().setLine(additionalArgs); 270 271 if (classpath != null) { 272 weblogicServer.setClasspath(classpath); 273 } 274 if (weblogicServer.executeJava() != 0) { 275 throw new BuildException("Execution of weblogic server failed"); 276 } 277 } 278 279 280 288 public void setClasspath(Path classpath) { 289 this.classpath = classpath; 290 } 291 292 300 public void setWlclasspath(Path weblogicClasspath) { 301 this.weblogicClasspath = weblogicClasspath; 302 } 303 304 311 public void setPolicy(String securityPolicy) { 312 this.securityPolicy = securityPolicy; 313 } 314 315 322 public void setHome(File weblogicHome) { 323 weblogicSystemHome = weblogicHome; 324 } 325 326 333 public void setBEAHome(File beaHome) { 334 this.beaHome = beaHome; 335 } 336 337 343 public void setName(String serverName) { 344 this.weblogicSystemName = serverName; 345 } 346 347 352 public void setDomain(String domain) { 353 this.weblogicDomainName = domain; 354 } 355 356 364 public void setProperties(String propertiesFilename) { 365 this.weblogicPropertiesFile = propertiesFilename; 366 } 367 368 372 public void setJvmargs(String args) { 373 this.additionalJvmArgs = args; 374 } 375 376 382 public void setUsername(String username) { 383 this.managementUsername = username; 384 } 385 386 387 392 public void setPassword(String password) { 393 this.managementPassword = password; 394 } 395 396 401 public void setPKPassword(String pkpassword) { 402 this.pkPassword = pkpassword; 403 } 404 405 410 public void setArgs(String args) { 411 additionalArgs = args; 412 } 413 414 418 public void setWeblogicMainClass(String c) { 419 weblogicMainClass = c; 420 } 421 } 422 | Popular Tags |