Java Jar Class Not Found Exception

元气小坏坏 提交于 2019-12-11 17:31:36

问题


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

main$4 not found.

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

Jar is created like the following.

  <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.


回答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 ?

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




回答2:


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

Main-Class should indicate the relative path to the class you want to run, e.g. "myPackage.Application", or simply "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.

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.

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.



来源:https://stackoverflow.com/questions/950636/java-jar-class-not-found-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!