可执行Jar:java.lang.ClassNotFoundException有时会在运行时触发

时间:2013-11-22 11:01:46

标签: java maven jar

我有一个使用Maven创建的可执行jar,使用如下的汇编插件:

        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <mainClass>org.htmlcleaner.GUI</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
           <executions>
            <execution>
              <id>make-assembly</id> <!-- this is used for inheritance merges -->
              <phase>package</phase> <!-- bind to the packaging phase -->
              <goals>
                <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

实际的Main方法如下所示:

public static void main(String[] args)  {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                new GUI();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });  
}

当我打包我的应用程序时,我得到一个jar-with-dependencies.jar,我可以通过双击来运行它。

但是,如果我然后退出或关闭应用程序,然后尝试再次运行它,我有时会在日志中看到ClassNotFoundException,并且应用程序无法启动。 (Exception与jar中依赖的类之一有关。它绝对存在。)

这种情况经常发生,但不是每次都发生。似乎是我在关闭它的大约10秒内尝试重新运行应用程序。

在桌面应用程序中使用Java时,这只是“其中一件事”吗?

0 个答案:

没有答案
相关问题