Archive for the ‘Eclipse’ Category

How to use couchapp with Eclipse

Dienstag, Oktober 19th, 2010

Couchapp is a simple toolkit to generate an initial web application based on CouchDB and JavaScript / JQuery. It also helps to update documents in CouchDB, which otherwise, using curl or futon, is quite painful.

Couchapp can be integrated in Eclipse in a straightforward way, so that the editors and viewers can be used to work with the CouchDB documents, and an automatic update gets triggered when a document was changed. Here is my recipe.

Create a new Eclipse workspace.

Create a new general Eclipse project in that workspace.

 

Use a terminal, go to the project directory and create the initial couchapp content:

couchapp generate <design_document>

 

Create two new variables which will be used to define the project builders:

Goto Window > Preferences > Run/Debug > String Substitution

Create a variable couchapp with the full path to the couchapp executable as value

Create a variable couch_url with the url to your couchdb database

 

Configure the couchapp push builder for the project:

Goto Project > Properties > Builders

Create a new builder

Edit the launch configuration properties:

In the Main tab enter couchapp_push as the name of the builder, select the variable ${couchapp} for the location, as working directory select ${workspace_loc:/<project_name>}, as arguments enter -v push ${workspace_loc:/<project_name>/<design_document>} ${couchdb_url}

In the tab Build Options check the option During auto builds, also specify <project_name>/<design_document> as working set of relevant resources

Click OK

 

Create a new folder docs in the project to hold the json documwnts which will be uploaded to the CouchDB.

 

Configure the couchapp push_docs builder for the project:

Goto Project > Properties > Builders

Create a new builder

Edit the launch configuration properties:

In the Main tab enter couchapp_pushdocs as the name of the builder, select the variable ${couchapp} for the location, as working directory select ${workspace_loc:/<project_name>}, as arguments enter -v pushdocs ${workspace_loc:/<project_name>/docs} ${couchdb_url}

In the tab Build Options check the option During auto builds, also specify <project_name>/docs as working set of relevant resources

Click OK

 

Associate json files to the Java Script Editor:

Goto Window > Preferences > General > Editors > File Associations

Select *.json from the File types and add the Java Script Editor as default editor.

 

Now if you change any document under the <design-document> or the docs directory, they are loaded into the CouchDB with each save .

 CouchApp in Eclipse