Macbook Pro(10.9.5)编译HelloWorld遇mgjava.jar无效压缩文件错误求助
Hey there, let's get this annoying issue sorted out for you! The problem is pretty straightforward: that mgjava.jar file in your Java Extensions directory is corrupted, and since Java automatically scans this folder for libraries to load, it's messing up even your simple HelloWorld compile—whether you use Eclipse or the command line.
Here's exactly what you need to do:
- Open Finder on your Mac, then press
Cmd + Shift + Gto bring up the "Go to Folder" dialog. - Paste in the path
/Users/myname/Library/Java/Extensions/(make sure to replacemynamewith your actual username) and hit Enter. - Find the
mgjava.jarfile in this folder. Drag it to your Trash (you can make a backup copy somewhere else first if you think you might need it later, but right now it's just causing problems). - Restart Eclipse if you're using it, then try compiling your HelloWorld program again. For the command line, just re-run your
javac HelloWorld.javaandjava HelloWorldcommands—they should work without that corrupted jar getting in the way.
Why this works:
Java checks the Extensions directory as part of its default classpath, regardless of what program you're compiling. Even if your HelloWorld doesn't use anything from mgjava.jar, the JVM still tries to read it—and since it's an invalid zip file (which is what a jar basically is), it throws that error. Removing the corrupted file eliminates the source of the problem entirely.
内容的提问来源于stack exchange,提问作者SeattleDucati

