Eclipse-jar创建失败“Class files on classpath not found or not accessible for…”?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (511)

我在Eclipse中有一个项目,它上面有一个红十字会,不会导出到一个可运行的JAR中。我不记得自从我在笔记本电脑上重新安装Windows之后,我是否看过它,但我知道我没有修改任何代码。在任何类中都没有错误,但是我得到的错误指向以下类,它处理MacOSX上的菜单项:

import java.lang.reflect.*;

public class osxhandler implements InvocationHandler {

      protected Object targetObject;
        protected Method targetMethod;
        protected String proxySignature;

        static Object macOSXApplication;

        // Pass this method an Object and Method equipped to perform application shutdown logic
        // The method passed should return a boolean stating whether or not the quit should occur
        public static void setQuitHandler(Object target, Method quitHandler) {
            setHandler(new HOsx("handleQuit", target, quitHandler));
        }


    public static void setAboutHandler(Object target, Method aboutHandler) {
        boolean enableAboutMenu = (target != null && aboutHandler != null);
        if (enableAboutMenu) {
            setHandler(new HOsx("handleAbout", target, aboutHandler));
        }
        // If we're setting a handler, enable the About menu item by calling
        // com.apple.eawt.Application reflectively
        try {
            Method enableAboutMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledAboutMenu", new Class[] { boolean.class });
            enableAboutMethod.invoke(macOSXApplication, new Object[] { Boolean.valueOf(enableAboutMenu) });
        } catch (Exception ex) {
            System.err.println("MacOSHandler could not access the About Menu");
            ex.printStackTrace();
        }
    }

       public static void setPreferencesHandler(Object target, Method prefsHandler) {
            boolean enablePrefsMenu = (target != null && prefsHandler != null);
            if (enablePrefsMenu) {
                setHandler(new HOsx("handlePreferences", target, prefsHandler));
            }
            // If we're setting a handler, enable the Preferences menu item by calling
            // com.apple.eawt.Application reflectively
            try {
                Method enablePrefsMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledPreferencesMenu", new Class[] { boolean.class });
                enablePrefsMethod.invoke(macOSXApplication, new Object[] { Boolean.valueOf(enablePrefsMenu) });
            } catch (Exception ex) {
                System.err.println("MacOSHandler could not access the About Menu");
                ex.printStackTrace();
            }
        }

        // Pass this method an Object and a Method equipped to handle document events from the Finder
        // Documents are registered with the Finder via the CFBundleDocumentTypes dictionary in the 
        // application bundle's Info.plist
        public static void setFileHandler(Object target, Method fileHandler) {
            setHandler(new HOsx("handleOpenFile", target, fileHandler) {
                // Override MacOSHandler.callTarget to send information on the
                // file to be opened
                public boolean callTarget(Object appleEvent) {
                    if (appleEvent != null) {
                        try {
                            Method getFilenameMethod = appleEvent.getClass().getDeclaredMethod("getFilename", (Class[])null);
                            String filename = (String) getFilenameMethod.invoke(appleEvent, (Object[])null);
                            this.targetMethod.invoke(this.targetObject, new Object[] { filename });
                        } catch (Exception ex) {

                        }
                    }
                    return true;
                }
            });
        }

        // setHandler creates a Proxy object from the passed MacOSHandler and adds it as an ApplicationListener
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public static void setHandler(HOsx adapter) {
            try {
                Class applicationClass = Class.forName("com.apple.eawt.Application");
                if (macOSXApplication == null) {
                    macOSXApplication = applicationClass.getConstructor((Class[])null).newInstance((Object[])null);
                }
                Class applicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
                Method addListenerMethod = applicationClass.getDeclaredMethod("addApplicationListener", new Class[] { applicationListenerClass });
                // Create a proxy object around this handler that can be reflectively added as an Apple ApplicationListener
                Object MacOSHandlerProxy = Proxy.newProxyInstance(HOsx.class.getClassLoader(), new Class[] { applicationListenerClass }, adapter);
                addListenerMethod.invoke(macOSXApplication, new Object[] { MacOSHandlerProxy });
            } catch (ClassNotFoundException cnfe) {
                System.err.println("This version of Mac OS X does not support the Apple EAWT.  ApplicationEvent handling has been disabled (" + cnfe + ")");
            } catch (Exception ex) {  // Likely a NoSuchMethodException or an IllegalAccessException loading/invoking eawt.Application methods
                System.err.println("Mac OS X Adapter could not talk to EAWT:");
                ex.printStackTrace();
            }
        }

        // Each MacOSHandler has the name of the EAWT method it intends to listen for (handleAbout, for example),
        // the Object that will ultimately perform the task, and the Method to be called on that Object
        protected HOsx(String proxySignature, Object target, Method handler) {
            this.proxySignature = proxySignature;
            this.targetObject = target;
            this.targetMethod = handler;
        }

        // Override this method to perform any operations on the event 
        // that comes with the various callbacks
        // See setFileHandler above for an example
        public boolean callTarget(Object appleEvent) throws InvocationTargetException, IllegalAccessException {
            Object result = targetMethod.invoke(targetObject, (Object[])null);
            if (result == null) {
                return true;
            }
            return Boolean.valueOf(result.toString()).booleanValue();
        }

        // InvocationHandler implementation
        // This is the entry point for our proxy object; it is called every time an ApplicationListener method is invoked
        public Object invoke (Object proxy, Method method, Object[] args) throws Throwable {
            if (isCorrectMethod(method, args)) {
                boolean handled = callTarget(args[0]);
                setApplicationEventHandled(args[0], handled);
            }
            // All of the ApplicationListener methods are void; return null regardless of what happens
            return null;
        }

        // Compare the method that was called to the intended method when the MacOSHandler instance was created
        // (e.g. handleAbout, handleQuit, handleOpenFile, etc.)
        protected boolean isCorrectMethod(Method method, Object[] args) {
            return (targetMethod != null && proxySignature.equals(method.getName()) && args.length == 1);
        }

        // It is important to mark the ApplicationEvent as handled and cancel the default behavior
        // This method checks for a boolean result from the proxy method and sets the event accordingly
        protected void setApplicationEventHandled(Object event, boolean handled) {
            if (event != null) {
                try {
                    Method setHandledMethod = event.getClass().getDeclaredMethod("setHandled", new Class[] { boolean.class });
                    // If the target method returns a boolean, use that as a hint
                    setHandledMethod.invoke(event, new Object[] { Boolean.valueOf(handled) });
                } catch (Exception ex) {
                    System.err.println("MacOSHandler was unable to handle an ApplicationEvent: " + event);
                    ex.printStackTrace();
                }
            }
        }    
}

对于为什么我不能导出/编译有什么想法吗?我以前从没遇到过这个问题

提问于
用户回答回答于

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/    org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2re1.4.2_03"/>

此外,您还可以检查project settings。右键单击项目并选择属性。转到JavaBuildPath,应该会有更多关于问题的具体信息。很可能您设置了新系统中不存在的JDK版本。如果这也没有帮助,请选择项目,然后使用菜单项Source->Clean Up.

热门问答

腾讯云广州一区DNS变更,需要怎么操作?

思潮澎湃轻描淡写的生活,但思潮澎湃
推荐
我也收到相关的通知了,这里分享下~ 2019年1月31日,腾讯云将对广州地区旧的基础网络DNS服务器(10.225.30.181、10.225.30.223)进行下线。在此期间,腾讯云提供最新的DNS服务器供您更新使用。 我们建议您尽快将DNS服务器配置进行更新,并且我们为您提供...... 展开详请

快照容量与费用的比例?如何关闭停用?

帅的惊动我国计算机大神
推荐已采纳
快照已于2019年1月22日0时启动正式商业化进程,商业化后所有存量快照和新产生的快照将根据快照使用的存储容量进行收费。 在快照商业化后,腾讯云仍旧会在国内主要地域为用户提供一定量的免费额度。免费额度策略如下: 免费额度覆盖范围为中国大陆地域,中国香港及海外地域暂无免费快照额...... 展开详请

无服务器云函数的cron表达式问题?

腾讯云serverless团队

腾讯云 · 产品团队 (已认证)

腾讯云无服务器云函数SCF产品
推荐
https://cloud.tencent.com/document/product/583/9708#cron-.E8.A1.A8.E8.BE.BE.E5.BC.8F.E8.AF.AD.E6.B3.95.E4.B8.80.EF.BC.88.E6.8E.A8.E8.8D.90.E...... 展开详请

云服务器-intelS2 标准入门型 带独立ip么?

Eli Qiao

腾讯 · 高级工程师 (已认证)

腾讯云CVM后台高级研发工程师
推荐

购买时,可以配置wan网ip,也可以之后添加eip

购买云服务器后上面的是否配套有数据库(mysql, sql server)和Web服务器等?

西风

renzha.net · 站长 (已认证)

www.renzha.net
推荐已采纳

买了服务器自己安装配置数据库即可,也可以另外选购性能更高,更安全可靠的云数据库。

无服务器云函数添加触发方式以错误码9000失败?

腾讯云serverless团队

腾讯云 · 产品团队 (已认证)

腾讯云无服务器云函数SCF产品
推荐

实在抱歉,最近这两天由于广州区 api 网关集群的配置量已超上限,导致 api 网关无法新增服务。目前 api 网关的研发同学已经在紧急扩容广州区集群了。

所属标签

扫码关注云+社区