tomcat 启动 java.lang.reflect.InvocationTargetException 什么情况,纠结

HUIQQ0927 2014-01-22 10:08:22
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:928)
at org.apache.tomcat.util.digester.SetNextRule.end(SetNextRule.java:193)
at org.apache.tomcat.util.digester.Rule.end(Rule.java:229)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1138)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1076)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4612)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.jsp in filter mapping
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2527)
... 46 more



...全文
538 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
HUIQQ0927 2014-01-22
  • 打赏
  • 举报
回复
引用 1 楼 defonds 的回复:
检查你的 web.xml 里 servlet 的配置



<filter>
		<filter-name>strutsfilter</filter-name>
		<!-- 在struts2-core.jar包中 -->
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
		<init-param>
			<param-name>struts.i18n.encoding</param-name>
			<param-value>gbk</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>strutsfilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
Defonds 2014-01-22
  • 打赏
  • 举报
回复
检查你的 web.xml 里 servlet 的配置
fw347969680 2014-01-22
  • 打赏
  • 举报
回复
引用 6 楼 HUIQQ0927 的回复:
引用 5 楼 fw347969680 的回复:
[quote=引用 4 楼 HUIQQ0927 的回复:] [quote=引用 3 楼 fw347969680 的回复:] Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.jsp in filter mapping。这就是错误的原因,现在没问题了?
不是啊,这个项目 我部署在resin 下正常的,tomcat 下 报错。
咦,错误里说是 /*.jsp,但是你的web.xml里是/*,怎么回事?[/quote]拦截action名称啊,现在项目是不允许手动通过url访问的。而我的action命名没有后缀的,直接是xxx,没有xxx.do,xxx.action。[/quote] 我不是指它的用途。。。我指代码和错误为什么不一致
HUIQQ0927 2014-01-22
  • 打赏
  • 举报
回复
引用 5 楼 fw347969680 的回复:
引用 4 楼 HUIQQ0927 的回复:
[quote=引用 3 楼 fw347969680 的回复:] Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.jsp in filter mapping。这就是错误的原因,现在没问题了?
不是啊,这个项目 我部署在resin 下正常的,tomcat 下 报错。
咦,错误里说是 /*.jsp,但是你的web.xml里是/*,怎么回事?[/quote]而且,我不说了么,项目在resin下面是可以启动运行的,我现在移植到tomcat下面,启动不了,我怀疑jar的问题。不解啊~
HUIQQ0927 2014-01-22
  • 打赏
  • 举报
回复
引用 5 楼 fw347969680 的回复:
引用 4 楼 HUIQQ0927 的回复:
[quote=引用 3 楼 fw347969680 的回复:] Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.jsp in filter mapping。这就是错误的原因,现在没问题了?
不是啊,这个项目 我部署在resin 下正常的,tomcat 下 报错。
咦,错误里说是 /*.jsp,但是你的web.xml里是/*,怎么回事?[/quote]拦截action名称啊,现在项目是不允许手动通过url访问的。而我的action命名没有后缀的,直接是xxx,没有xxx.do,xxx.action。
fw347969680 2014-01-22
  • 打赏
  • 举报
回复
引用 4 楼 HUIQQ0927 的回复:
引用 3 楼 fw347969680 的回复:
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.jsp in filter mapping。这就是错误的原因,现在没问题了?
不是啊,这个项目 我部署在resin 下正常的,tomcat 下 报错。
咦,错误里说是 /*.jsp,但是你的web.xml里是/*,怎么回事?
HUIQQ0927 2014-01-22
  • 打赏
  • 举报
回复
引用 3 楼 fw347969680 的回复:
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.jsp in filter mapping。这就是错误的原因,现在没问题了?
不是啊,这个项目 我部署在resin 下正常的,tomcat 下 报错。
fw347969680 2014-01-22
  • 打赏
  • 举报
回复
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.jsp in filter mapping。这就是错误的原因,现在没问题了?
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.startup; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.catalina.Globals; import org.apache.catalina.security.SecurityClassLoad; import org.apache.catalina.startup.ClassLoaderFactory.Repository; import org.apache.catalina.startup.ClassLoaderFactory.RepositoryType; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; /** * Bootstrap loader for Catalina. This application constructs a class loader * for use in loading the Catalina internal classes (by accumulating all of the * JAR files found in the "server" directory under "catalina.home"), and * starts the regular execution of the container. The purpose of this * roundabout approach is to keep the Catalina internal classes (and any * other classes they depend on, such as an XML parser) out of the system * class path and therefore not visible to application level classes. * * @author Craig R. McClanahan * @author Remy Maucherat */ public final class Bootstrap { private static final Log log = LogFactory.getLog(Bootstrap.class); /** * Daemon object used by main. */ private static Bootstrap daemon = null; private static final File catalinaBaseFile; private static final File catalinaHomeFile; private static final Pattern PATH_PATTERN = Pattern.compile("(\".*?\")|(([^,])*)"); static { // Will always be non-null //System.getProperty("user.dir"),获取当前目录 //由于是在$CATALINA_HOME\bin下运行的Bootstrap,所以userDir为$CATALINA_HOME\bin String userDir = System.getProperty("user.dir"); // Home first //Globals是存放全局常量的类 //Globals.CATALINA_HOME_PROP = "catalina.home" //catalina.home在运行Bootstrap时已设置(Tomcat的根目录) String home = System.getProperty(Globals.CATALINA_HOME_PROP); File homeFile = null; //获取Tomcat的绝对路径 if (home != null) { File f = new File(home); try { homeFile = f.getCanonicalFile(); } catch (IOException ioe) { homeFile = f.getAbsoluteFile(); } } if (homeFile == null) { // First fall-back. See if current directory is a bin directory // in a normal Tomcat install File bootstrapJar = new File(userDir, "bootstrap.jar"); if (bootstrapJar.exists()) { File f = new File(userDir, ".."); try { homeFile = f.getCanonicalFile(); } catch (IOException ioe) { homeFile = f.getAbsoluteFile(); } } } if (homeFile == null) { // Second fall-back. Use current directory File f = new File(userDir); try { homeFile = f.getCanonicalFile(); } catch (IOException ioe) { homeFile = f.getAbsoluteFile(); } } //设置catalinaHomeFile catalinaHomeFile = homeFile; System.setProperty( Globals.CATALINA_HOME_PROP, catalinaHomeFile.getPath()); // Then base String base = System.getProperty(Globals.CATALINA_BASE_PROP); //设置catalinaBaseFile if (base == null) { catalinaBaseFile = catalinaHomeFile; } else { File baseFile = new File(base); try { baseFile = baseFile.getCanonicalFile(); } catch (IOException ioe) { baseFile = baseFile.getAbsoluteFile(); } catalinaBaseFile = baseFile; } System.setProperty( Globals.CATALINA_BASE_PROP, catalinaBaseFile.getPath()); } // -------------------------------------------------------------- Variables /** * Daemon reference. */ private Object catalinaDaemon = null; protected ClassLoader commonLoader = null; protected ClassLoader catalinaLoader = null; protected ClassLoader sharedLoader = null; // -------------------------------------------------------- Private Methods private void initClassLoaders() { try { //创建commonLoader commonLoader = createClassLoader("common", null); if( commonLoader == null ) { // no config file, default to this loader - we might be in a 'single' env. commonLoader=this.getClass().getClassLoader(); } //创建catalinaLoader、sharedLoader catalinaLoader = createClassLoader("server", commonLoader); sharedLoader = createClassLoader("shared", commonLoader); } catch (Throwable t) { handleThrowable(t); log.error("Class loader creation threw exception", t); System.exit(1); } } private ClassLoader createClassLoader(String name, ClassLoader parent) throws Exception { //CatalinaProperties解析$CATALINA_HOME\conf\catalina.properties, //并将catalina.properties内的属性存为系统属性 //catalina.properties内common.loader="${catalina.base}/lib", //"${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar" //读取common.loader String value = CatalinaProperties.getProperty(name + ".loader"); if ((value == null) || (value.equals(""))) return parent; //将${catalina.base},${catalina.home}替换为Tomcat的绝对路径 value = replace(value); List repositories = new ArrayList<>(); String[] repositoryPaths = getPaths(value); for (String repository : repositoryPaths) { // Check for a JAR URL repository try { @SuppressWarnings("unused") URL url = new URL(repository); repositories.add( new Repository(repository, RepositoryType.URL)); continue; } catch (MalformedURLException e) { // Ignore } // Local repository if (repository.endsWith("*.jar")) { repository = repository.substring (0, repository.length() - "*.jar".length()); repositories.add( new Repository(repository, RepositoryType.GLOB)); } else if (repository.endsWith(".jar")) { repositories.add( new Repository(repository, RepositoryType.JAR)); } else { repositories.add( new Repository(repository, RepositoryType.DIR)); } } //ClassLoaderFactory依据repositories的内容创建ClassLoader return ClassLoaderFactory.createClassLoader(repositories, parent); } /** * System property replacement in the given string. * * @param str The original string * @return the modified string */ protected String replace(String str) { // Implementation is copied from ClassLoaderLogManager.replace(), // but added special processing for catalina.home and catalina.base. String result = str; int pos_start = str.indexOf("${"); if (pos_start >= 0) { StringBuilder builder = new StringBuilder(); int pos_end = -1; while (pos_start >= 0) { builder.append(str, pos_end + 1, pos_start); pos_end = str.indexOf('}', pos_start + 2); if (pos_end < 0) { pos_end = pos_start - 1; break; } String propName = str.substring(pos_start + 2, pos_end); String replacement; if (propName.length() == 0) { replacement = null; } else if (Globals.CATALINA_HOME_PROP.equals(propName)) { replacement = getCatalinaHome(); } else if (Globals.CATALINA_BASE_PROP.equals(propName)) { replacement = getCatalinaBase(); } else { replacement = System.getProperty(propName); } if (replacement != null) { builder.append(replacement); } else { builder.append(str, pos_start, pos_end + 1); } pos_start = str.indexOf("${", pos_end + 1); } builder.append(str, pos_end + 1, str.length()); result = builder.toString(); } return result; } /** * Initialize daemon. */ public void init() throws Exception { //创建commonLoader、catalinaLoader、sharedLoader initClassLoaders(); //为当前线程设置ClassLoader Thread.currentThread().setContextClassLoader(catalinaLoader); //设置SecurityClassLoad。具体作用还不清楚。。。 SecurityClassLoad.securityClassLoad(catalinaLoader); // Load our startup class and call its process() method if (log.isDebugEnabled()) log.debug("Loading startup class"); //通过反射实例化Catalina Class startupClass = catalinaLoader.loadClass ("org.apache.catalina.startup.Catalina"); Object startupInstance = startupClass.newInstance(); // Set the shared extensions class loader if (log.isDebugEnabled()) log.debug("Setting startup class properties"); String methodName = "setParentClassLoader"; Class paramTypes[] = new Class[1]; paramTypes[0] = Class.forName("java.lang.ClassLoader"); Object paramValues[] = new Object[1]; paramValues[0] = sharedLoader; //通过反射设置Catalina的parentClassLoader Method method = startupInstance.getClass().getMethod(methodName, paramTypes); method.invoke(startupInstance, paramValues); //将实例化的Catalina赋值给catalinaDaemon catalinaDaemon = startupInstance; } /** * Load daemon. */ private void load(String[] arguments) throws Exception { // Call the load() method //调用catalinaDaemon的load方法,并传递参数"start" String methodName = "load"; Object param[]; Class paramTypes[]; if (arguments==null || arguments.length==0) { paramTypes = null; param = null; } else { paramTypes = new Class[1]; paramTypes[0] = arguments.getClass(); param = new Object[1]; param[0] = arguments; } Method method = catalinaDaemon.getClass().getMethod(methodName, paramTypes); if (log.isDebugEnabled()) log.debug("Calling startup class " + method); method.invoke(catalinaDaemon, param); } /** * getServer() for configtest */ private Object getServer() throws Exception { String methodName = "getServer"; Method method = catalinaDaemon.getClass().getMethod(methodName); return method.invoke(catalinaDaemon); } // ----------------------------------------------------------- Main Program /** * Load the Catalina daemon. */ public void init(String[] arguments) throws Exception { init(); load(arguments); } /** * Start the Catalina daemon. */ public void start() throws Exception { if( catalinaDaemon==null ) init(); //调用catalinaDaemon的start方法 Method method = catalinaDaemon.getClass().getMethod("start", (Class [] )null); method.invoke(catalinaDaemon, (Object [])null); } /** * Stop the Catalina Daemon. */ public void stop() throws Exception { Method method = catalinaDaemon.getClass().getMethod("stop", (Class [] ) null); method.invoke(catalinaDaemon, (Object [] ) null); } /** * Stop the standalone server. */ public void stopServer() throws Exception { Method method = catalinaDaemon.getClass().getMethod("stopServer", (Class []) null); method.invoke(catalinaDaemon, (Object []) null); } /** * Stop the standalone server. */ public void stopServer(String[] arguments) throws Exception { Object param[]; Class paramTypes[]; if (arguments==null || arguments.length==0) { paramTypes = null; param = null; } else { paramTypes = new Class[1]; paramTypes[0] = arguments.getClass(); param = new Object[1]; param[0] = arguments; } Method method = catalinaDaemon.getClass().getMethod("stopServer", paramTypes); method.invoke(catalinaDaemon, param); } /** * Set flag. */ public void setAwait(boolean await) throws Exception { //通过反射,设置catalinaDaemon的await Class paramTypes[] = new Class[1]; paramTypes[0] = Boolean.TYPE; Object paramValues[] = new Object[1]; paramValues[0] = Boolean.valueOf(await); Method method = catalinaDaemon.getClass().getMethod("setAwait", paramTypes); method.invoke(catalinaDaemon, paramValues); } public boolean getAwait() throws Exception { Class paramTypes[] = new Class[0]; Object paramValues[] = new Object[0]; Method method = catalinaDaemon.getClass().getMethod("getAwait", paramTypes); Boolean b=(Boolean)method.invoke(catalinaDaemon, paramValues); return b.booleanValue(); } /** * Destroy the Catalina Daemon. */ public void destroy() { // FIXME } /** * Main method and entry point when starting Tomcat via the provided * scripts. * * @param args Command line arguments to be processed */ public static void main(String args[]) { if (daemon == null) { // Don't set daemon until init() has completed //***2.1*** Bootstrap bootstrap = new Bootstrap(); try { //***2.2*** bootstrap.init(); } catch (Throwable t) { handleThrowable(t); t.printStackTrace(); return; } //***2.3*** daemon = bootstrap; } else { // When running as a service the call to stop will be on a new // thread so make sure the correct class loader is used to prevent // a range of class not found exceptions. Thread.currentThread().setContextClassLoader(daemon.catalinaLoader); } //***2.4*** try { String command = "start"; if (args.length > 0) { command = args[args.length - 1]; } if (command.equals("startd")) { args[args.length - 1] = "start"; daemon.load(args); daemon.start(); } else if (command.equals("stopd")) { args[args.length - 1] = "stop"; daemon.stop(); } else if (command.equals("start")) { //***2.5*** daemon.setAwait(true); //***2.6*** daemon.load(args); //***2.7*** daemon.start(); } else if (command.equals("stop")) { daemon.stopServer(args); } else if (command.equals("configtest")) { daemon.load(args); if (null==daemon.getServer()) { System.exit(1); } System.exit(0); } else { log.warn("Bootstrap: command \"" + command + "\" does not exist."); } } catch (Throwable t) { // Unwrap the Exception for clearer error reporting if (t instanceof InvocationTargetException && t.getCause() != null) { t = t.getCause(); } handleThrowable(t); t.printStackTrace(); System.exit(1); } } /** * Obtain the name of configured home (binary) directory. Note that home and * base may be the same (and are by default). */ public static String getCatalinaHome() { return catalinaHomeFile.getPath(); } /** * Obtain the name of the configured base (instance) directory. Note that * home and base may be the same (and are by default). If this is not set * the value returned by {@link #getCatalinaHome()} will be used. */ public static String getCatalinaBase() { return catalinaBaseFile.getPath(); } /** * Obtain the configured home (binary) directory. Note that home and * base may be the same (and are by default). */ public static File getCatalinaHomeFile() { return catalinaHomeFile; } /** * Obtain the configured base (instance) directory. Note that * home and base may be the same (and are by default). If this is not set * the value returned by {@link #getCatalinaHomeFile()} will be used. */ public static File getCatalinaBaseFile() { return catalinaBaseFile; } // Copied from ExceptionUtils since that class is not visible during start private static void handleThrowable(Throwable t) { if (t instanceof ThreadDeath) { throw (ThreadDeath) t; } if (t instanceof VirtualMachineError) { throw (VirtualMachineError) t; } // All other instances of Throwable will be silently swallowed } // Protected for unit testing protected static String[] getPaths(String value) { List result = new ArrayList<>(); Matcher matcher = PATH_PATTERN.matcher(value); while (matcher.find()) { String path = value.substring(matcher.start(), matcher.end()); path = path.trim(); if (path.startsWith("\"") && path.length() > 1) { path = path.substring(1, path.length() - 1); path = path.trim(); } if (path.length() == 0) { continue; } result.add(path); } return result.toArray(new String[result.size()]); } }

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧