0

It seems that when I rebuild a jar file that one of my Eclipse projects depends upon, Eclipse doesn't notice that the jar has been modified, and doesn't rebuild the project. I subsequently have to do a manual clean build.

Specifically, I'm building the jar from within Eclipse using the technique given in this answer and keeping it in a directory outside my workspace projects.

The reason I am using the jar as a dependency instead of having the main project depend on the second project directly is because the main project is in Java and the jar project is in Scala. I've found the Scala builds to be very slow, so I decided to keep the project closed and manually build the jar from within Eclipse whenever I make changes to the Scala project.

Is this lack of "external jar modification" detection an Eclipse bug/limitation or is there a way to enable this behavior?

Community
  • 1
  • 1
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
  • I do not think if it is possible in Eclipse. But a dependency management system like Maven or Ivy will go a long way in solving this problem and also remove unwanted ide dependencies in build cycle. – uncaught_exceptions Sep 15 '11 at 19:32
  • Please provide more details where this jar is located or post content of .classpath file from the root of your project. – Eugene Kuleshov Sep 15 '11 at 19:35
  • @Eugine, I don't understand the relevance of where the jar resides, but it's in a local directory outside my project workspace, as configured in the project properties settings, Java Build Path, libraries tab. – Jeff Axelrod Sep 15 '11 at 19:38

4 Answers4

1

The problem likely that jar is outside of your Eclipse Workspace, so Eclipse can't see the changes. You need to modify jar location and/or project's Java Build Path configuration to bring jar inside Workspace.

A better alternative is to have sources for that jar as another Eclipse project and have that other project as dependency, so you won't have to rebuild jar for every change.

Eugene Kuleshov
  • 31,461
  • 5
  • 66
  • 67
  • So if instead of keeping the jar outside of my project, I move it inside my project, Eclipse will recognize the file modification? This seems like a strange requirement. – Jeff Axelrod Sep 15 '11 at 19:50
  • Actually the opposite, nothing strange. Basically the whole point of Workspace for Eclipse is to be able to track resource changes, e.g. for incremental compilation. This jar is one of the resources, so Eclipse need to see its changes. – Eugene Kuleshov Sep 15 '11 at 19:52
  • Wait, now I'm really confused. You're saying that if the jar is inside my project, Eclipse won't notice the file modification, but if I keep it outside the project, as it is already, Eclipse should rebuild upon jar update? – Jeff Axelrod Sep 15 '11 at 19:54
  • Sorry about confusion. The jar should be in the workspace, but not necessarily inside of your project. But if jar is updated from outside of Eclipse you'll have to refresh corresponding folder in workspace or enable "Refresh automatically" in Preferences / General / Workspace. – Eugene Kuleshov Sep 15 '11 at 19:56
  • OK, so specifically, I'm building the jar from within Eclipse using the technique given in [this answer](http://stackoverflow.com/questions/1062941/build-project-into-a-jar-automatically-in-eclipse/1066223#1066223). If I have to keep it in my workspace, I'd rather not create an empty project just to hold the jar. Are you saying that Eclipse won't recognize the changes if I put the jar in the project that's dependent on the jar? – Jeff Axelrod Sep 15 '11 at 20:06
0

Unless I'm missing something entirely, you can just right-click on the jar file in your project, and then click "Refresh". It works in Eclipse Juno at least.

ChopperCharles
  • 747
  • 2
  • 9
  • 19
0

I'd suggest using a build tool - like Maven - that will manage dependencies like this. Eclipse has support for building Maven projects.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
0

I think this is probably more of a worklflow thing. Having eclipse scanning all dependencies at all times for changes would probably be quite heavyweight.

If you are not using eclipse to build some part of your project, it would seem reasonable that when you execute whatever action to modify its dependencies, that you should refresh your project/workspace in order for eclipse to pick up the changes. I use maven, so for me when I build, maven builds my code, analyses the external dependencies and rewrites my .project and .classpath files. I refresh my workspace and everything is up to date.

My only other suggestion is, if you are in control of the changes to that dependency, add the source as a project to eclipse and add it as a project dependency in eclipse, not a jar dependency.

markdsievers
  • 7,151
  • 11
  • 51
  • 83
  • The reason I am using the JAR as a dependency is because I'm mixing Java and Scala. I've found the Scala builds to be very slow, so I decided to keep the project closed and manually build the jar from within Eclipse whenever I make changes to the Scala project. – Jeff Axelrod Sep 15 '11 at 19:49