If Eclipse refuses to generate class files

If Eclipse Indigo Release 2 is mad and refuses to compile any Java files which have no problems at all, here is the solution.

First, go to the log file to check the detailed problem. Don’t go to the Window>Show View>Problems. Sometimes it may reflect something. For me, it is useless. So we locate the problem by checking log file. The log file is under your workspace. There is a folder named .metadata. In the folder, there is a file named .log. That is it. Open it by text editor.

Commonly it shows your problem at the beginning. My problem log is:

!SESSION 2015-08-28 16:54:11.030 ———————————————–
eclipse.buildId=M20120208-0800
java.version=1.7.0_25
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

This is a continuation of log file E:\GMU workspace\.metadata\.bak_0.log
Created Time: 2015-08-28 17:02:20.048

!ENTRY org.eclipse.jdt.core 4 4 2015-08-28 17:02:20.049
!MESSAGE JavaBuilder handling ImageBuilderInternalException while building: WorkflowCore
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Problems encountered while copying resources.
at org.eclipse.core.internal.localstore.FileSystemResourceManager.copy(FileSystemResourceManager.java:314)
at org.eclipse.core.internal.resources.Resource.copy(Resource.java:542)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.copyResource(AbstractImageBuilder.java:379)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder$3.visit(BatchImageBuilder.java:222)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:65)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:75)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.copyExtraResourcesBack(BatchImageBuilder.java:191)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.cleanOutputFolders(BatchImageBuilder.java:119)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:46)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:173)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:513)
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:432)
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:305)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Contains: Could not write file: E:\GMU workspace\WorkflowCore\build\classes\wsdl_list_1.txt.
java.io.FileNotFoundException: E:\GMU workspace\WorkflowCore\build\classes\wsdl_list_1.txt (拒绝访问。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at org.eclipse.core.internal.filesystem.local.LocalFile.openOutputStream(LocalFile.java:382)
at org.eclipse.core.filesystem.provider.FileStore.copyFile(FileStore.java:221)
at org.eclipse.core.filesystem.provider.FileStore.copy(FileStore.java:143)
at org.eclipse.core.internal.filesystem.local.LocalFile.copy(LocalFile.java:111)
at org.eclipse.core.internal.localstore.CopyVisitor.copyContents(CopyVisitor.java:100)
at org.eclipse.core.internal.localstore.CopyVisitor.copy(CopyVisitor.java:71)
at org.eclipse.core.internal.localstore.CopyVisitor.visit(CopyVisitor.java:202)
at org.eclipse.core.internal.localstore.UnifiedTree.accept(UnifiedTree.java:110)
at org.eclipse.core.internal.localstore.FileSystemResourceManager.copy(FileSystemResourceManager.java:311)
at org.eclipse.core.internal.resources.Resource.copy(Resource.java:542)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.copyResource(AbstractImageBuilder.java:379)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder$3.visit(BatchImageBuilder.java:222)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:65)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:75)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.copyExtraResourcesBack(BatchImageBuilder.java:191)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.cleanOutputFolders(BatchImageBuilder.java:119)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:46)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:173)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:513)
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:432)
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:305)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

We can see the reason is that Eclipse cannot correctly copy and write the class files into the default classpath. Wow, it seems eclipse is innocent! It has no permission to write files into the folder. I have no idea who is blocking poor eclipse to copy compiled class files into the target folder (/build/classes by default). But it doesn’ t matter. We can avoid this by using another class output folder.

So the solution is : right click your eclipse project, click Properties. Select Java Build Path. Switch to the Source tab and change the class output folder to a different one. Just like the following image shows.

Snap6

Then, let’s test it. Click Project>Clean&Build Project. Finally, I see the class files in the new output folder. Thank god!

One sentence conclusion, always remember log file is the correctest information we can know about problems!

 

One thought on “If Eclipse refuses to generate class files

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s