atteo / classindex

Index classes, do not scan them!
Apache License 2.0
263 stars 42 forks source link

Not working with Eclipse? #5

Closed nkavian closed 11 years ago

nkavian commented 11 years ago

I created a new Java project in Eclipse, added the evo and guava jars, followed the example in the "Usage", but I don't see any index file being generated and it doesn't print out what it's supposed to print out.

What am I missing?

Using evo-classindex-1.3.jar and guava-14.0.1.jar

It only print out the first line, not the others:

  System.out.println("!!!! Hello");
  for(final Class<?> klass : ClassIndex.getAnnotated(Entity.class))
     {
     System.out.println("!!!! " + klass.getName());
     }

Eclipse Juno on a Mac

sentinelt commented 11 years ago

Eclipse uses its own Java compiler which is not strictly standard compliant and requires extra configuration. See screenshot below: eclipse_screenshot

sentinelt commented 11 years ago

Instructions from Eclipse page: http://www.eclipse.org/jdt/apt/introToAPT.php

Let me know if that helps. I will add relevant info to the README file.

nkavian commented 11 years ago

Thanks so much, I'm so excited that this is going to work. I found that screen but would never have figured out to load both jars. I ran into another error afterwards when using this with a Java EE Tomcat 7 project. I found out to turn off "Serve modules without publishing" because when it was enabled it would cause this exception:

java.lang.RuntimeException: Evo Class Index: Cannot read class index at org.atteo.evo.classindex.ClassIndex.readIndexFile(ClassIndex.java:174) ...... Caused by: java.io.FileNotFoundException: /Website/Java/WebContent/WEB-INF/classes/META-INF/annotations/model.internal.client.Entity (No such file or directory) at java.io.FileInputStream.open(Native Method) ......

During compilation, the output was in: /Website/Java/build/classes/META-INF/annotations/model.internal.client.Entity

But when run it expects it in: /Website/Java/WebContent/WEB-INF/classes/META-INF/annotations/model.internal.client.Entity

A few links that kind of talk about similar problems but no solutions except to disable the feature: http://stackoverflow.com/questions/5924720/serve-modules-without-publishing-not-working-in-helios https://github.com/SpringSource/spring-mvc-showcase/issues/18

Any chance you have a solution?

nkavian commented 11 years ago

In this file I think there needs to be a try/catch inside the first while loop before the second while loop to avoid an exception from breaking the iteration..

If the first URL resources throws an IOException then it will not scan the rest of the URL resources..

https://github.com/atteo/evo-classindex/blob/master/classindex/src/main/java/org/atteo/evo/classindex/ClassIndex.java

I noticed the exception referenced ClassIndex line 154..

Caused by: java.io.FileNotFoundException: /Website/Java/WebContent/WEB-INF/classes/META-INF/annotations/model.internal.client.Entity (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:138) at java.io.FileInputStream.(FileInputStream.java:97) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188) at java.net.URL.openStream(URL.java:1035) at org.atteo.evo.classindex.ClassIndex.readIndexFile(ClassIndex.java:154) ... 25 more

This may be why my earlier problem happend..?..

Part of the solution may just be ignoring the IOException and return an empty classes list.

sentinelt commented 11 years ago

So there really is some index file because it is returned from getResources method in ClassIndex line 150, but somehow it cannot be opened.

Would You be able to provide me with a sample project with which I could reproduce the issue?

sentinelt commented 11 years ago

Thanks, for the sample project.

sentinelt commented 11 years ago

Fixed in 1.4. Thanks for all your support.

sentinelt commented 10 years ago

As of version 3.0 it is no longer necessary to load Guava in Eclipse, because ClassIndex was rewritten to not use it.