вторник, 31 января 2012 г.

Running executable jar file in windows vista or windows 7

In Windows Vista or Windows 7 the manual file association editor has been removed. So you can have problems with running executable jar by double-clicking it. You can solve it in different ways:
1) Most easiest way is to use program Jarfix
2) Also you can add file association in your command prompt window using "Run as administrator”:
          C:\>assoc .jar=jarfile
          C:\>ftype jarfile="C:\path\to\your\javaw.exe" -jar "%1" %*

среда, 25 января 2012 г.

Resolving problems with running Apache Nutch on Windows. Part 2.

When Nutch crawling process started with '-solr' argument you can face a problem with Solr schema.xml.Some fields can be absent and you will see errors in log:
2012-01-25 11:03:46,484 WARN  mapred.LocalJobRunner - job_local_0020
org.apache.solr.common.SolrException: ERROR: [doc=http://business.ngs.ru/] unknown field 'content'

ERROR: [doc=http://business.ngs.ru/] unknown field 'content'

request: http://localhost:8983/solr/update?wt=javabin&version=2
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:436)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:245)
    at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
    at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:49)
    at org.apache.nutch.indexer.solr.SolrWriter.close(SolrWriter.java:93)
    at org.apache.nutch.indexer.IndexerOutputFormat$1.close(IndexerOutputFormat.java:48)
    at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:474)
    at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:411)
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:216)



To fix this I've copied schema.xml for Solr from http://svn.apache.org/viewvc/nutch/branches/branch-1.4/conf/schema.xml?view=markup.

вторник, 24 января 2012 г.

Resolving problems with running Apache Nutch on Windows. Part 1.

First root of some problems with running Apache Nutch on Windows is Cygwin, as Nutch has bash scripts to run. So, install Cygwin and add its root directory to 'path' system variable (e.g. C:\Cygwin). But if you added only root directory to path you can see exception in Nutch log:

java.io.IOException: Expecting a line not the end of stream
    at org.apache.hadoop.fs.DF.parseExecResult(DF.java:109)
    at org.apache.hadoop.util.Shell.runCommand(Shell.java:179)
    at org.apache.hadoop.util.Shell.run(Shell.java:134)
    at org.apache.hadoop.fs.DF.getAvailable(DF.java:73)
    at org.apache.hadoop.fs.LocalDirAllocator$AllocatorPerContext.getLocalPathForWrite(LocalDirAllocator.java:329)
    at org.apache.hadoop.fs.LocalDirAllocator.getLocalPathForWrite(LocalDirAllocator.java:124)
    at org.apache.hadoop.mapred.MapOutputFile.getSpillFileForWrite(MapOutputFile.java:107)
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:1221)
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1129)
    at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:359)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:307)
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:177)


To resolve this you should add Cygwin 'bin' directory to your system path (e.g. C:\Cygwin\bin)

среда, 18 января 2012 г.

Disabled fields in ExtJS form

If you want to disable input field in your form, don't make it:


disabled: true
In this case value of the field won't be submitted (this is standard
behaviour for HTML forms). Insted of this use: 

readOnly: true,
fieldClass: "x-item-disabled"
 In this case field value will be submitted but field itself will look
 like disabled and will be not editable. 

среда, 11 января 2012 г.

GIT - working on a side branch

It is best to work on a side branch and follow the “merge master/merge side” delivery procedure.  The overall flow is defined here:
Here is refined set of commands, which details branch switch, and substitutes rebases on the side branch instead of merges:

1. Starting on local master, update from remote master then create a side branch

git pull origin
git checkout -b JIRA-1122 origin/master
2. Now on side branch named JIRA-1122

git commit -m "blah"
git pull --rebase origin/master
Notice that I’ve told it to rebase

3. Back to local master branch

git checkout master
git pull origin
This updates your local master to mirror what the upstream master looks like.
 4.

git merge JIRA-1122
Your changes are merged onto master not the other way around: 
git push origin master

5. You may now throw away the side branch.

git branch -d JIRA-1122

понедельник, 9 января 2012 г.

Hibernate Search re-index

I had to solve problem with re-indexing recipes for my own russian cooking portal cook365.ru when I add new entries from MySql dump to database on live server. So I added this method in my service implementation class.

    @Transactional
    public List<Recipe> reindexAll() {

        List<Recipe> recipes = recipeDao.findAll();

        EntityManager entityManager = entityManagerFactory.createEntityManager();

        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);

        for (Recipe recipe : recipes) {

            recipe = fullTextEntityManager.merge(recipe);

            fullTextEntityManager.index(recipe);

        }

        fullTextEntityManager.flushToIndexes();

        return recipes;

    }



At first time I didn't added fullTextEntityManager.flushToIndexes(); and indexes were not updated, spent some time to figure out the problem.

среда, 28 декабря 2011 г.

About this blog

About this blog shortly  - "Java" means that author is Java developer, "NSK" stands for Novosibirsk, russian big city, where I live. Here I will share some solutions from my work, that could be helpful for other java or android developers.