|
Java example source code file (Invoker.java)
The Invoker.java Java example source code/* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.internal.ws; import com.sun.istack.internal.tools.MaskingClassLoader; import com.sun.istack.internal.tools.ParallelWorldClassLoader; import com.sun.tools.internal.ws.resources.WscompileMessages; import com.sun.tools.internal.ws.wscompile.Options; import com.sun.tools.internal.xjc.api.util.ToolsJarNotFoundException; import com.sun.xml.internal.bind.util.Which; import javax.xml.ws.Service; import javax.xml.ws.WebServiceFeature; import javax.xml.namespace.QName; import java.io.File; import java.io.OutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Invokes JAX-WS tools in a special class loader that can pick up annotation processing classes, * even if it's not available in the tool launcher classpath. * * @author Kohsuke Kawaguchi */ public final class Invoker { /** * The list of package prefixes we want the * {@link MaskingClassLoader} to prevent the parent * classLoader from loading */ static final String[] maskedPackages = new String[]{ "com.sun.istack.internal.tools.", "com.sun.tools.internal.jxc.", "com.sun.tools.internal.xjc.", "com.sun.tools.internal.ws.", "com.sun.codemodel.internal.", "com.sun.relaxng.", "com.sun.xml.internal.xsom.", "com.sun.xml.internal.bind.", "com.ctc.wstx.", //wsimport, wsgen ant task "org.codehaus.stax2.", //wsimport, wsgen ant task "com.sun.xml.internal.messaging.saaj.", //wsgen ant task "com.sun.xml.internal.ws.", "com.oracle.webservices.internal.api." //wsgen }; /** * Escape hatch to work around IBM JDK problem. * See http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?nav=false&forum=367&thread=164718&cat=10 */ public static final boolean noSystemProxies; static { boolean noSysProxiesProperty = false; try { noSysProxiesProperty = Boolean.getBoolean(Invoker.class.getName()+".noSystemProxies"); } catch(SecurityException e) { // ignore } finally { noSystemProxies = noSysProxiesProperty; } } static int invoke(String mainClass, String[] args) throws Throwable { // use the platform default proxy if available. // see sun.net.spi.DefaultProxySelector for details. if(!noSystemProxies) { try { System.setProperty("java.net.useSystemProxies","true"); } catch (SecurityException e) { // failing to set this property isn't fatal } } ClassLoader oldcc = Thread.currentThread().getContextClassLoader(); try { ClassLoader cl = Invoker.class.getClassLoader(); if(Arrays.asList(args).contains("-Xendorsed")) cl = createClassLoader(cl); // perform JDK6 workaround hack else { int targetArgIndex = Arrays.asList(args).indexOf("-target"); Options.Target targetVersion; if (targetArgIndex != -1) { targetVersion = Options.Target.parse(args[targetArgIndex+1]); } else { targetVersion = Options.Target.getDefault(); } Options.Target loadedVersion = Options.Target.getLoadedAPIVersion(); //Check if the target version is supported by the loaded API version if (!loadedVersion.isLaterThan(targetVersion)) { if (Service.class.getClassLoader() == null) System.err.println(WscompileMessages.INVOKER_NEED_ENDORSED(loadedVersion.getVersion(), targetVersion.getVersion())); else { System.err.println(WscompileMessages.WRAPPER_TASK_LOADING_INCORRECT_API(loadedVersion.getVersion(), Which.which(Service.class), targetVersion.getVersion())); } return -1; } //find and load tools.jar List<URL> urls = new ArrayList Other Java examples (source code examples)Here is a short list of links related to this Java Invoker.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.