简体   繁体   English

带有Jaudiotagger,NoClassDefFoundError的Jar文件

[英]Jar file with Jaudiotagger, NoClassDefFoundError

I made a java class using the library Jaudiotagger, and it runs without problems. 我使用库Jaudiotagger创建了一个Java类,它可以正常运行。 I then made a jar out of it and I got NoClassDefFoundError. 然后,我用它制成了一个罐子,并得到了NoClassDefFoundError。 Here's how it went: 这是怎么回事:

I put the main class id3tag.java and the library jaudiotagger-2.0.3.jar in a folder and compiled using the command line. 我将主类id3tag.java和库jaudiotagger-2.0.3.jar放在一个文件夹中,并使用命令行进行了编译。 The program ran smoothly without problems. 该程序运行顺利,没有问题。

javac -cp .;jaudiotagger-2.0.3.jar id3tag.java
java -cp .;jaudiotagger-2.0.3.jar id3tag

I then created the manifest and the jar file. 然后,我创建了清单和jar文件。

echo Main-Class: id3tag >manifest.txt
jar cvfm id3tag.jar manifest.txt id3tag.class jaudiotagger-2.0.3.jar

I got the following output: 我得到以下输出:

added manifest
adding: id3tag.class(in = 5952) (out= 2997)(deflated 49%)
adding: jaudiotagger-2.0.3.jar(in = 811441) (out= 740599)(deflated 8%)

I then ran the jar file, and got "A Java Exception has occurred.". 然后,我运行jar文件,并得到“发生Java异常”。 I also tried: 我也尝试过:

java -jar id3tag.jar

And I got the output: 我得到了输出:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/tag/
FieldDataInvalidException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
        at java.lang.Class.getMethod0(Class.java:2694)
        at java.lang.Class.getMethod(Class.java:1622)
        at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)

Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.tag.FieldDataInval
idException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 6 more

I then replaced all (both) error classes used from Jaudiotagger with Exception and recreated the jar. 然后,我用Exception替换了Jaudiotagger中使用的所有(两个)错误类,并重新创建了jar。 Now the same thing happens as for seemingly all other jar files when I run them (with Java(TM) Platform SE binary, or through writing id3tag.jar in the command prompt) - nothing. 现在,似乎所有其他jar文件(使用Java™Platform SE二进制文件,或通过在命令提示符下编写id3tag.jar)运行时,都发生了相同的事情-没事。 java -jar, however, works and gave me a runtime error. 但是,java -jar有效并且给了我一个运行时错误。

Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/audi
o/AudioFileIO
        at id3tag.tagSong(id3tag.java:112)
        at id3tag.tagAlbum(id3tag.java:82)
        at id3tag.tagArtist(id3tag.java:40)
        at id3tag.main(id3tag.java:170)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.audio.AudioFileIO
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 4 more

It seems like the entire library just doesn't do shit for me. 似乎整个图书馆对我来说都不是坏事。 How do I fix this, and how do I get jar files to run without java -jar? 如何解决此问题,以及如何在不使用Java -jar的情况下运行jar文件? (Also, how do I get the full pile'o'errors in case someone needs it, rather than just having it say "x more"?) (此外,如果有人需要它,而不是仅仅说“ x多”,我如何获得全部错误)?

I'm not very savvy with this kinda shit so the more specific the answer, the better. 我不太了解这种答案,所以答案越具体越好。 Thanks. 谢谢。

I'm on windows 8 and latest java (1.7.0_17). 我在Windows 8和最新的Java(1.7.0_17)上。

this is informing you that you have no main class, as you might or might not already know all programs in almost all non web based programming languages must have a main class to start from. 这是在通知您您没有主类,因为您可能已经或可能不知道几乎所有非基于Web的编程语言中的所有程序都必须具有主类。 In java it looks like this 在java中看起来像这样

public static int main(String[] args){ public static int main(String [] args){

} }

The message is informing you that this class is no longer there, this could be a compiler error or something entirely different. 消息通知您该类不再存在,这可能是编译器错误或完全不同的东西。

please try downloading the library again, and downloading eclipse ide for java ee developers. 请尝试再次下载该库,然后为Java ee开发人员下载eclipse ide。 this ide has a built in compiler that will work better than a command line sometimes. 这个想法有一个内置的编译器,有时会比命令行更好。

i hope this helped. 我希望这会有所帮助。

I worked around it by including the org folder from jaudiotagger in my .jar instead of the actual .jar file, and I then used a .bat file to run it instead of running the .jar directly. 我通过将jaudiotagger的org文件夹(而不是实际的.jar文件)包含在我的.jar文件中来解决此问题,然后使用.bat文件运行该文件,而不是直接运行.jar文件。 Feel free to add your own answer if you find a better solution, and I'll check back. 如果您找到更好的解决方案,请随时添加您自己的答案,我会再检查。

I extracted jaudiotagger-2.0.3.jar with winrar so that the org folder was in the same folder as my main class. 我用winrar提取了jaudiotagger-2.0.3.jar,以便org文件夹与我的主类位于同一文件夹中。 Then I could compile and run the main class simply by: 然后,我可以通过以下方式简单地编译和运行主类:

javac id3tag.java
java id3tag

I then created the manifest file the same way as before, and created the jar: 然后,我以与以前相同的方式创建清单文件,并创建了jar:

jar cvfm id3tag.jar manifest.txt id3tag.class org

The jar file worked with java -jar id3tag.jar, but simply writing id3tag.jar still did nothing. 该jar文件可与java -jar id3tag.jar一起使用,但仅编写id3tag.jar仍无济于事。 Turns out it's because jar files are by default run by the javaw.exe file, so you have to right click the jar file -> open with -> choose default program and navigate to the java.exe file in your java folder (just search the folder). 原来是因为jar文件默认是由javaw.exe文件运行的,所以您必须右键单击jar文件->使用-打开,然后选择默认程序,然后导航到java文件夹中的java.exe文件(只需搜索文件夹)。 Running the .jar then gets you "Error: Could not find or load main class path\\id3tag.jar". 运行.jar然后会得到“错误:找不到或加载主类路径\\ id3tag.jar”。 I worked around this by using a .bat file. 我通过使用.bat文件来解决此问题。 I entered 我进入了

java -jar path\id3tag.jar

into Notepad and saved as whatevername.bat (save as type: all files). 放入记事本并另存为whatname.bat(另存为:所有文件)。

I created a new question for getting the .jar file to work properly. 我为使.jar文件正常工作创建了一个新问题。 See .jar error - could not find or load main class . 请参阅.jar错误-找不到或加载主类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM