Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting Java project as .jar file will complain that certain .java files aren't found

Tags:

java

eclipse

When trying to export a project as a .jar file, Eclipse will complain that some files can't be found on the classpath:

Class files on classpath not found or not accessible for: 'proj/src/main/java/analysis/specification/VerifyVariableIsDefinedInsideTargetTerm.java'

Now, the interesting part is that these files haven't actually existed on the disk for ages. I guess I force Eclipse to refresh its database some way. I've tried doing F5 for a full build, but it seems to no avail. I've also tried the procedure described in this blog post, but the issue remains.

like image 542
devoured elysium Avatar asked Aug 26 '12 01:08

devoured elysium


2 Answers

Error… I actually tripped on the reason for the problem a few moments ago…

All the files that were raising problems did actually exist on the project but were commented out (and thus, I didn't see them in the package explorer which is the view I generally use).

After deleting them, everything went fine. I still don't understand why would they raise errors in the JAR creation process, though…

EDIT: Here's an example of a commented out class:

package a.b.c

//import java.io.Closeable;

//public class Example implements Closeable {
//    public void close() throws IOException {
//        System.out.println("closed");
//    }
//}

Because the whole class is commented out, no Example.class is created. Whereas if the class is commented out like this:

package a.b.c

//import java.io.Closeable;

public class Example
//    implements Closeable
{
//    public void close() throws IOException {
//        System.out.println("closed");
//    }
}

an Example.class is created, although empty.

This may be a bug in eclipse. If you export the ant build script from eclipse and use that, it creates the JAR just fine.

like image 96
devoured elysium Avatar answered Oct 15 '22 23:10

devoured elysium


This issue occurred to me also. However, the problem that I had was that I had JRE configuration issues in Eclipse.

like image 22
Nirav Radia Avatar answered Oct 15 '22 22:10

Nirav Radia