简体   繁体   中英

How to make Eclipse/Counterclockwise use Macports installed Clojure

I'm very new to clojure and after some hours fiddling with Netbeans/Enclojure and Eclipse/Counterclockwise I finally set for Eclipse/Counterclockwise - just because it was the first one I was able to get running actually.

But, in the REPL, I get Clojure version 1.2, although the one I got working in my system (with Macports ) is 1.3.

How do I make Eclipse/Counterclockwise use this version? I can't find basically anything about Clojure in the preferences, except for the syntax highlight rules and some other minor stuff.

Basically, the Clojure version the Eclipse/CCW REPL uses is the Clojure version that's included in the classpath of the project you start the REPL from. If you include it in the referenced libraries of your project, the REPL will start with that version of Clojure.

You can include it by rightclicking the project name in the Package Explorer > Properties > Java Build Path > Add Jars > Browse to (Macport) clojure jar file > Finish.

However, since you need to do this for all external libraries and the libraries they themselves depend on (be they Java or Clojure based), this can get tedious, and even worse, will not work when building a project for distribution.

The easiest way to get it done in a structural way, is using Leiningen in combination with the Leiningen CCW plugin. First install Leiningen as per the leiningen page. Then call lein plugin install lein-ccw "1.2.0" to install the leiningen CCW plugin.

If you are starting on a new project, cd to the parent directory the project should be put in. Then, use lein new projectname , which will create a new Clojure project structure in the \\projectname subdir.

In the root of this project a project.clj file will have been made that's used to manage and download the libraries you want to use, and all libraries they themselves depend on (see leiningen site for more details). A reference to Clojure will have been put there by lein new as default.

The libraries will be stored in a local library repository, and so will only be written to disk once.

cd into the \\projectname subdir and run lein deps and leiningen will download the current dependencies (in this case only clojure), and put them in the repository.

Now run lein ccw , and the ccw lein plugin will create and update an Eclipse project and classpath file.

After this you can open the project in Eclipse by choosing menu File > Import > General > Import Existing Projects Into Workspace > Select Root Directory > Browse to Project Location > Finish.

Now if you need a new library for your project, the only thing you need to do is put the library data in the project.clj dependency section. The dependency notation and version numbers of other libraries can be found on the Clojars site or in Github readme's of libraries.

Then, just run lein deps again from the project dir to download and install the correct libraries, and lein ccw to update your Eclipse project and classpath files. Refresh the project tree in the Eclipse Package Explorer, and your project is up to date again, including all new libraries you needed.

You can even automate the steps in the above paragraph by creating an 'External Run Configuration' in Eclipse by following this guide , creating the lein ccw run command in the same way as, or adding it to the lein deps one. This way you only need to push one button after editing the project.clj and all steps will be executed by Eclipse.

After you get the hang of these basic steps, you can start exploring other uses of Leiningen, like building your project for distribution / deployment.

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