【问题标题】:Exported Javafx application does not run as Jar file (Eclipse)导出的 Javafx 应用程序不作为 Jar 文件运行 (Eclipse)
【发布时间】:2017-05-21 03:45:27
【问题描述】:

我有一个 javafx 应用程序没有正确地从 eclipse 导出到一个可运行的 jar 文件。导出时,.jar 文件无法正常运行并且 GUI 不会出现。下面是清单文件。

Manifest-Version: 1.0
Class-Path: .
Main-Class: gameaspects.SourceCodeVersion9

导出界面如下:

导出文件不会产生来自 eclipse 的错误或警告。

从 cmd 运行应用程序出现以下错误:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at                 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.file.NoSuchFileException: .\music
    at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(Unknown Source)
    at sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(Unknown Source)
    at sun.nio.fs.WindowsFileSystemProvider.readAttributes(Unknown Source)
    at java.nio.file.Files.readAttributes(Unknown Source)
    at java.nio.file.FileTreeWalker.getAttributes(Unknown Source)
    at java.nio.file.FileTreeWalker.visit(Unknown Source)
    at java.nio.file.FileTreeWalker.walk(Unknown Source)
    at java.nio.file.FileTreeIterator.<init>(Unknown Source)
    at java.nio.file.Files.find(Unknown Source)
    at gameaspects.SourceCodeVersion9.start(SourceCodeVersion9.java:81)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    ... 1 more

异常运行应用程序gameaspects.SourceCodeVersion9

我认为这是指的代码是这样的:

List<String> result = Files.find(Paths.get(".\\music"), 100,
        (p, a) -> p.toString().toLowerCase().endsWith(".mp3"))
        .map(path -> path.toString())
        .collect(Collectors.toList());

.\music 指的是我的应用程序中存在的源文件夹 music

如果需要任何其他信息来诊断此问题,请在下方评论,我会添加。

【问题讨论】:

  • @fabian 编辑问题以提供错误。
  • 好的,使用我发现的 cmd 提供的错误并修复了错误。但是,我想知道如何将 List 方法更改为不对同一个文件命名两次。
  • 顺便说一句:无论如何默认路径都是相对的。添加.\\ : Paths.get("music") 没有意义。至于文件重复:使用Stream.distinct,或者如果您有现有列表,请使用Set,遍历列表并删除set.add(element)返回false的所有元素

标签: java eclipse javafx jar manifest


【解决方案1】:

好的,在命令提示符下使用java -jar FileName.jar,然后使用堆栈跟踪来调试我的代码,我能够在我的应用程序中找到错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-04
    • 2016-11-05
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    相关资源
    最近更新 更多