简体   繁体   中英

Auto import new Java classes added to project path on startup in Eclipse

For simplicists: You can only read the bold part.

I'm using Dropbox (for those of you who don't know what Dropbox is: it is a service that creates a universal folder that is stored online but can be accessed on any computer and changes are reflected to all.) to store my Java Eclipse Project. So, when I add a new Java Class to the Dropbox from home, it shows in the Dropbox folder in the office computer. However, I have to import it to Eclipse to view it. Is there a way that the files I add from home can be imported to Eclipse automatically? Maybe Eclipse has a setting that searches all the Java files in the Project directory on every startup and auto imports them? Any ideas?

In its simplest form (regardless of Dropbox), the question is: Is there a setting that auto imports new Java classes added to my project path into Eclipse?

You can either create the entire project in your Dropbox, or you can "link" your project to a source directory in your Dropbox. (Use the Build Path / Link Source… context menu on your project.)

Eclipse only looks for new files in its directories at well-specified times; it doesn't poll for new files. So, if Eclipse is already running with Dropbox syncs a new file to the project, you'll have to "refresh" your project for Eclipse to notice it.


Update: Linking shouldn't alter the behavior; it is just a way to allow you to include source files that aren't located under your project directory, if you didn't want to keep your whole project in Dropbox.

"Import" actually creates copies of files. Refreshing the directory should be sufficient if the files are actually present in your project directory; importing would suggest that they are being copied from another location. Also, if you try to use Import / File System to import files to their current location, it won't allow it (giving the error message "Source is in the hierarchy of the destination.") If you are able to complete this import, it is further evidence that the files referenced by your project are not stored in your Dropbox.

So I question whether any part of your project is actually stored in Dropbox. Right-click one of the source files that you've successfully imported to your project; look at its Properties . By looking at the full path, you should be able to see if it really is located in Dropbox. Maybe it is actually a copy located inside your Eclipse workspace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM