Miscellaneous

!! Re-execute previous command.
!27 Execute command 27 in the history (look it up with: history | tail)
Ctrl + R Reverse search in history (type Ctrl + R to search incrementally)
Ctrl + L Clear the terminal. The same as typing clear
Ctrl + M Enter/return. Useful if inside a long command.
Ctrl + S/Q Freeze terminal/Restore frozen terminal

Move and View Commands

Ctrl + A Go to begin of line (mnemonic: “Anfang” (DE))
Ctrl + E Go to end of line (mnemonic: “end”)
Ctrl + F or Arrow Right Forward one character.
Ctrl + B or Arrow Left Backward one character.
Alt + F or Ctrl + Arrow Right Forward one word.
Alt + B or Ctrl + Arrow Left Backward one word.
Shift + Page Up/Page Down Scroll view up/down one page

Edit Commands

Ctrl + K Delete from cursor to end of line
Ctrl + U Delete from cursor to begin of line
Ctrl + W Delete word left of cursor
Alt + D Delete word right of cursor
Ctrl + D Delete character under cursor or exit bash if line is empty.

Maven-managed Eclipse projects generate appropriate project settings (classpath, build path, etc.) from the pom.xml. The following files need to be ignored in a Maven Eclipse project:

.settings
.project
.classpath
target/

As a shorthand, the following Bash command adds these lines to your .gitignore. It does not matter if your .gitignore is located in the project directory or in any parent of it.

echo “.settings
.project
.classpath
target/” >> .gitignore

Links

  • [1] gitignore man page

CMake projects in Qt creator can be prepared for debugging in different ways. One possibility which does not touch the CMake file is to use the Projects configuration view. Thanks to Mirko Windhoff whose instructions pointed me at that solution:

  1. Open up the Projects view
  2. Select Add Custom Build Step
    • Command: /usr/bin/cmake (for Unices)
    • Arguments: -DCMAKE_BUILD_TYPE=Debug .
    • Working Directory: %{buildDir} (or %BUILDDIR)
  3. Make sure the new build step is executed before the call to make as CMake generates the Makefile. Shift up the build step with the buttons at the top of the box.
  4. Start debugging with F5.

I ran across the use case described in the title when working with a legacy web application which also serves as a dependency for other (plugin) projects. To this end, besides the War file which is deployed as web application, I would like to have the contained Jar file being installed separately in my local repository.

This additional artifact can be obtained with a few lines in the pom.xml:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-install-plugin</artifactId>
  <version>2.4</version>
  <executions>
      <execution>
          <phase>install</phase>
          <goals>
              <goal>install-file</goal>
          </goals>
          <configuration>
              <packaging>jar</packaging>
              <artifactId>${project.artifactId}</artifactId>
              <groupId>${project.groupId}</groupId>
              <version>${project.version}</version>
              <file>
                  ${project.build.directory}/${project.build.finalName}/WEB-INF/lib/${project.artifactId}-${project.version}.jar
              </file>
          </configuration>
      </execution>
  </executions>
</plugin>

This execution extracts the Jar file which is produced during the preparations of the War file and installs it with the project’s default group id, artifact id, and version.

Links

  • [1] Maven Install Plugin: install-file

By a “Maven web project” I mean a Maven project which has War packaging instead of Jar (in pom.xml: <project><packaging>war</packaging></project>). When importing such projects, Eclipse may not be able to figure out that the produced War artifact may be deployed on a server.

Maven may configure your Eclipse project to support WTP:

mvn -Dwtpversion=2.0 eclipse:eclipse

This goal can also be run inside Eclipse when you right-click the project and then select: Run as -> Maven build… As goal you type in eclipse:eclipse and add a new line in the parameter table where the parameter name is wtpversion and the value is 2.0.

Running the eclipse:eclipse goal for an existing project does not affect any unrelated settings in you project.

Links

  • [1] Maven eclipse plugin: WTP Support

The version control system Subversion offers a nice feature called keywords. Keywords are a mechanism which allows to replace certain markers/placeholders in versioned text files with SVN metadata (author, last modified date, last modified revision, etc.). By default, keywords are disabled and may be activated with a specific SVN property called svn:keywords.  The corresponding chapter in the SVN book lists the available Keywords.

Keywords (in the example, the last modified date and revision) may either be activated for a single file:

svn propset svn:keywords "Date Revision" testfile.txt

or for a whole directory tree

svn propset svn:keywords "Date Revision" -R .

As of the next commit of the files, all occurrences of $Date$ and $Revision$ placeholders will be updated with the up-to-date metadata every time you commit the file:

$Date: 2013-05-01 10:08:40 +0200 (Wed, 01 May 2013) $
$Revision: 11 $

If you want to disable all keywords for a file/tree you use the propdel command:

svn propdel svn:keywords testfile.txt
svn propdel svn:keywords -R .

For disabling certain keywords there exists the propedit command which fires up a text editor:

svn propedit svn:keywords testfile.tx

Note that propedit only works for a single file/directory and has, by nature, no recursive option. A recursive alternative is to use propset svn:keywords -R with a new list of SVN keywords.

The following is a list of my favorite keywords:

Keyword| Placeholder| Example
Date $Date$ $Date: 2013-05-01 10:08:40 +0200 (Wed, 01 May 2013) $
Revision $Revision$ $Revision: 11 $
Author $Author$ $Revision: svenlogan $

Links

  • [1] SVN Keyword Substitution (Svnbook)

The toolkit uimaFIT allows you to design annotation types in the so-called Component Descriptor Editor, save the descriptor as XML and generate the corresponding Java classes. When you run an analysis engine that makes use of these annotations uimaFit checks whether it finds the type system descriptor XML file on the classpath. In certain circumstances, it may happen that it falls short of finding this file and will abort with the following error message:

Caused by: org.apache.uima.cas.CASRuntimeException: 
JCas type "de.tudarmstadt.ukp.teaching.nlp4web.ml.type.NamedEntity" used in Java code, but was not declared in the XML type descriptor.
    at org.apache.uima.jcas.impl.JCasImpl.getType(JCasImpl.java:412)
    at org.apache.uima.jcas.cas.TOP.<init>(TOP.java:92)
    at org.apache.uima.jcas.cas.AnnotationBase.<init>(AnnotationBase.java:53)
    at org.apache.uima.jcas.tcas.Annotation.<init>(Annotation.java:54)

In this case you need to explicitly point uimaFIT to the location of your type descriptor file. For this to be done, there exist two different ways.

Solution via VM argument

As a quick and dirty solution you add the following VM argument which in Eclipse is configured in the Launch Configuration dialog

-Dorg.uimafit.type.import_pattern=classpath*:desc/types/**/*.xml

In my case, I stored the XML file in src/main/resources/desc/types/TypeSystem.xml where src/main/resources is set to be a source folder in Eclipse (Maven project layout).

Solution via types.txt (suggested)

The issue with the solution above is that your code will break if other people try to execute it without knowing about the VM parameter. There exists a more stable way to solve this issue. uimaFIT looks into the file

  • <classpath>/META-INF/org.uimafit/types.txt  (for uimaFit until 1.4.x, still supported by the uimafit-legacy-support package)
  • <classpath>/META-INF/org.apache.uima.fit/types.txt (for uimaFit 2.0.0 and above)

in order to find out where to search for the XML type descriptor files (In a Maven context META-INF should be located in src/main/resources). Each line in this types.txt file describes one search pattern. In our example, types.txt should contain one line:

classpath*:desc/types/**/*.xml

Links

  • [1] uimaFit Guide and Reference – 8.1. Making types auto-detectable
  • [2] DKPro tutorial (UIMA part): Type System Auto-Discovery (Slide 37)
  • [3] TypeDescriptorDetection

Some image processing programs expect the file extension to be in lower case. Many digital cameras, however, tend to use an uppercase extension (JPG in case of the Panasonic TZ-31).

The following Bash one-liner renames all JPG files in the current folder to have the lowercase jpg extension afterwards. The ${…} expression is called parameter expansion, which is quite a powerful mechanism:

for file in *.JPG; do  mv $file "${file%.*}.jpg"; done

Links

  • [1] Manpage of the Bash (see Section on Parameter Expansion)
  • [2] Parameter Expansion explained on bash-hackers.org

Maven is not only great for dependency management, you can also download jars (which are called “artifacts” in Maven parlor) directly using the dependency:get goal.

The only thing you have to have in mind is the full artifact id which is easy to remember for prominent libraries such as the Apache Commons (org.apache.commons:commons-XX:VERSION) or Spring (org.springframework:spring-XX:VERSION).

As an example, the following command download the Apache Commons Math3 library (3.0) and stores it as /tmp/commons-math3.jar:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get 
   -Dartifact=org.apache.commons:commons-math3:3.0    
   -Ddest=/tmp/commons-math3.jar

Even though this one-lines seems to be simple, it took me some time to figure out how this command works:

  • Make sure you use the fully qualified plugin name and version 2.4. Otherwise the -Ddest parameter will not work.
  • The -Ddest parameter needs to be a filename, not a directory. The denoted file is overwritten in case of conflict.

Some Useful Artifacts to remember

If you want to look up the artifact id of an artifact then take a look at the Maven Central Search. Just some examples:

  • org.apache.commons:commons-math3:3.0
  • org.apache.commons:commons-io:1.3.2
  • junit:junit:4.10

Links

  • [1] dependency:get Reference
  • [2] Maven Central Search

If you have executions in your pom.xml which run during so-called interesting build phases. You need to provide a rule how m2eclipse shall deal with these executions (<execute/>,<ignore/>,<delegate/>).

The following snippet may be put into the pom.xml in order allow for the dependency plugin to run the goal build-classpath (Mind the <execute/> directive):

<build>
<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.eclipse.m2e</groupId>
      <artifactId>lifecycle-mapping</artifactId>
      <version>1.0.0</version>
      <configuration>
        <lifecycleMappingMetadata>
          <pluginExecutions>
            <pluginExecution>
              <pluginExecutionFilter>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <versionRange>[1.0.0,)</versionRange>
                <goals>
                  <goal>build-classpath</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <execute/>
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>
</build>

It is very(!) important to give a version range, otherwise a NullPointerException will be thrown.

Links

  • [1] Site on “M2E plugin execution not covered”
  • [2] List of “m2eclipse interesting build executions”