程序很简单,就是从使用反射,从一个存在的class里面读出来所有的methods,程序如下import java.lang.reflect.*;
import java.net.URL;
import java.net.URLClassLoader;
public class SAXStruts_config {
public static void main(String args[]) {
try {
URLClassLoader urlcl = new URLClassLoader(new URL[]{new URL("file://f:/ref/")});
Class c = urlcl.loadClass("com.oreilly.struts.storefront.order.ShoppingCartActions"); Method m[] = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++)
System.out.println(m[i].getName());
} catch (Throwable e) {
System.err.println(e);
}
}
}可是编译的时候总会报
java.lang.NoClassDefFoundError: org/apache/struts/actions/DispatchAction看起来好像是classpath的问题,刚接触反射,不太熟悉,谢谢下面是ShoppingCartActions
package com.oreilly.struts.storefront.order;import java.io.IOException;
import java.text.Format;
import java.text.NumberFormat;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;
import com.oreilly.struts.storefront.service.IStorefrontService;
import com.oreilly.struts.storefront.catalog.view.ItemDetailView;
import com.oreilly.struts.storefront.framework.UserContainer;
import com.oreilly.struts.storefront.framework.util.IConstants;
import com.oreilly.struts.storefront.framework.ShoppingCartItem;
import com.oreilly.struts.storefront.framework.ShoppingCart;
import com.oreilly.struts.storefront.framework.StorefrontDispatchAction;
/**
* Implements all of the functionality for the ShoppingCart.
*/
public class ShoppingCartActions extends DispatchAction {
/**
* This method just forwards to the success state, which should represent
* the shoppingcart.jsp page.
*/
public ActionForward view(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {。。
import java.net.URL;
import java.net.URLClassLoader;
public class SAXStruts_config {
public static void main(String args[]) {
try {
URLClassLoader urlcl = new URLClassLoader(new URL[]{new URL("file://f:/ref/")});
Class c = urlcl.loadClass("com.oreilly.struts.storefront.order.ShoppingCartActions"); Method m[] = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++)
System.out.println(m[i].getName());
} catch (Throwable e) {
System.err.println(e);
}
}
}可是编译的时候总会报
java.lang.NoClassDefFoundError: org/apache/struts/actions/DispatchAction看起来好像是classpath的问题,刚接触反射,不太熟悉,谢谢下面是ShoppingCartActions
package com.oreilly.struts.storefront.order;import java.io.IOException;
import java.text.Format;
import java.text.NumberFormat;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;
import com.oreilly.struts.storefront.service.IStorefrontService;
import com.oreilly.struts.storefront.catalog.view.ItemDetailView;
import com.oreilly.struts.storefront.framework.UserContainer;
import com.oreilly.struts.storefront.framework.util.IConstants;
import com.oreilly.struts.storefront.framework.ShoppingCartItem;
import com.oreilly.struts.storefront.framework.ShoppingCart;
import com.oreilly.struts.storefront.framework.StorefrontDispatchAction;
/**
* Implements all of the functionality for the ShoppingCart.
*/
public class ShoppingCartActions extends DispatchAction {
/**
* This method just forwards to the success state, which should represent
* the shoppingcart.jsp page.
*/
public ActionForward view(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {。。
看看你下载的struts相关的包,你确定已经把他们都引用到你的工程文件中???
需要把struts的相关jar包全部引入到classpath,用JB等IDE开发的话,引入到工程的libpath就可以了