Java Jar类未找到异常

时间:2023-01-12 15:44:54

I can build my application cleanly on windows and Mac OS X but on windows when i try to run the application i get a class not found exception about my main class

我可以在Windows和Mac OS X上干净地构建我的应用程序但在Windows上尝试运行应用程序时,我得到一个关于我的主类的类找不到异常

main$4 not found.

主要$ 4未找到。

class is there and it build cleanly. why can't it locate the class file? Jar works in OS X.

班级在那里,它建立得干净利落。为什么不能找到类文件? Jar在OS X中运行。

Jar is created like the following.

Jar的创建方式如下。

  <target name="jar" depends="">
  <jar destfile="build/application.jar" > 
    <manifest>
      <attribute name="Built-By" value="Hamza"/>
      <attribute name="Main-Class" value="application"/>
    </manifest>
    <fileset dir="build">
      <include name="**/*.class"/>
  <include name="**/*.png"/> 
      <exclude name="**/*.jar"/>
    </fileset>
  </jar>
</target>

i can run it without any errors on OS X but in Windows i get class not found exceptions.

我可以在OS X上运行它而没有任何错误但在Windows中我得到类未找到异常。

3 个解决方案

#1


Is it run with the same JVM ? main$4 seems to indicate it's an anonymous class which is not found. Hard to help you without more information. Maybe provide a piece of code and some stacktrace, and the JRE versions you're using ?

它是使用相同的JVM运行的吗? main $ 4似乎表明它是一个没有找到的匿名类。没有更多信息,很难帮助你。也许提供一段代码和一些堆栈跟踪,以及你正在使用的JRE版本?

Typo there : cleanly on windows and Mac OS X but on windows

错字:在Windows和Mac OS X上干净利落地在窗户上

#2


Is the Main-Class attribute really set to "application"?

Main-Class属性是否真的设置为“application”?

Main-Class should indicate the relative path to the class you want to run, e.g. "myPackage.Application", or simply "Main".

Main-Class应指明要运行的类的相对路径,例如“myPackage.Application”,或简称为“Main”。

#3


Not much information, but it looks like an anonymous class in your main class cannot resolve some dependency it has and thus cannot be created.

信息不多,但看起来主类中的匿名类无法解决它所具有的依赖性,因此无法创建。

Also, there is a difference between your build time and runtime class paths. Your actual runtime can potentially require more jars than the build.

此外,您的构建时间和运行时类路径之间存在差异。您的实际运行时可能需要比构建更多的jar。

For example, a jar containing an interface that you reference in your code would be required for your code to build, but you will require jars with the implementations of that interface for your code to run.

例如,构建代码需要包含代码中引用的接口的jar,但是您需要具有该接口实现的jar来运行代码。

EDIT: Your update shows your build, which you already said works (which OS doesn't matter) as this is Java. Your problem is the classpath at runtime. Do you have a classpath environment variable set in one OS and not the other? We cannot tell from this what your dependencies are. Knowing the contents of the anonymous classes involved would help figure out what dependency is missing.

编辑:您的更新显示您的构建,您已经说过工作(哪个操作系统无关紧要),因为这是Java。您的问题是运行时的类路径。您是否在一个操作系统中设置了类路径环境变量而不是另一个?我们无法从中了解您的依赖关系。了解所涉及的匿名类的内容将有助于找出缺少的依赖项。

#1


Is it run with the same JVM ? main$4 seems to indicate it's an anonymous class which is not found. Hard to help you without more information. Maybe provide a piece of code and some stacktrace, and the JRE versions you're using ?

它是使用相同的JVM运行的吗? main $ 4似乎表明它是一个没有找到的匿名类。没有更多信息,很难帮助你。也许提供一段代码和一些堆栈跟踪,以及你正在使用的JRE版本?

Typo there : cleanly on windows and Mac OS X but on windows

错字:在Windows和Mac OS X上干净利落地在窗户上

#2


Is the Main-Class attribute really set to "application"?

Main-Class属性是否真的设置为“application”?

Main-Class should indicate the relative path to the class you want to run, e.g. "myPackage.Application", or simply "Main".

Main-Class应指明要运行的类的相对路径,例如“myPackage.Application”,或简称为“Main”。

#3


Not much information, but it looks like an anonymous class in your main class cannot resolve some dependency it has and thus cannot be created.

信息不多,但看起来主类中的匿名类无法解决它所具有的依赖性,因此无法创建。

Also, there is a difference between your build time and runtime class paths. Your actual runtime can potentially require more jars than the build.

此外,您的构建时间和运行时类路径之间存在差异。您的实际运行时可能需要比构建更多的jar。

For example, a jar containing an interface that you reference in your code would be required for your code to build, but you will require jars with the implementations of that interface for your code to run.

例如,构建代码需要包含代码中引用的接口的jar,但是您需要具有该接口实现的jar来运行代码。

EDIT: Your update shows your build, which you already said works (which OS doesn't matter) as this is Java. Your problem is the classpath at runtime. Do you have a classpath environment variable set in one OS and not the other? We cannot tell from this what your dependencies are. Knowing the contents of the anonymous classes involved would help figure out what dependency is missing.

编辑:您的更新显示您的构建,您已经说过工作(哪个操作系统无关紧要),因为这是Java。您的问题是运行时的类路径。您是否在一个操作系统中设置了类路径环境变量而不是另一个?我们无法从中了解您的依赖关系。了解所涉及的匿名类的内容将有助于找出缺少的依赖项。