(filtered by tag 'hint')

I am posting this because I was not able to find anything on Net. Even I consider it now to belong into category obvious.

I am working on obfuscation of our project and was bitten by following exception when trying to use the obfuscated JAR:

java.lang.ClassFormatError: StackMapTable format error: bad class index

StackMapTable is feature of Java to provide faster class verification and you cannot configure Klassmaster what to do about it as you can with any proper class.

Eventually I found it works when built locally, but fails with version built by a build server. That helped me to find the culprit.

Solution

We were using old version of Zelix Klassmaster on server due to incorrect default home directory of Klassmaster. After changing path to use version 5.3 it works. It works also with 5.2.4b.

Generating ANTLR classes from Ant

Added: April 29, 2010

Tags: ANTLR DSL book hint

I am in the middle or reading Domain Specific Languages by Martin Fowler and I have started to experiment with ANTLR today. After copy&pasting of example and fixing a few problems I wanted to generate a parser from grammar. I wanted to use following Ant snippet taken from Ant documentation (Rough Cuts of the book does not show how to do that):

	<target name="generate" depends="prepare">
		<antlr target="${dir.antlr.src}/Greetings.g" outputdirectory="${dir.gen}" />
	</target>
But regardless of my experiments ANTLR process invoked from Ant always ended with Unable to determine generated class. Googling did not help. I found many questions, but no solution. Finally I settled on a following workaround, based on standalone generation of sources from the grammar:
	<target name="generate" depends="prepare">
		<java jar="lib/antlr-3.2.jar" fork="true">
			 <arg value="-o"/>
			 <arg value="${dir.gen}"/>
			 <arg value="${dir.antlr.src}/Greetings.g"/>
		</java>
	</target>
This does the trick. Now back to the example to see what it does.

I had some problems to search for all necessary details so I am going to publish my little script here as it might be useful for somebody.

In my work I need to keep several console windows open (on Windows) in order to produce jar artefacts from several dependent projects without a need to use our build server. Sometimes it got a bit out of control when I needed 6 or 8 of them opened at the same time and was not easy to find partcular one quickly. So I have decided to create a script that changes console title to working directory (only last directory).

ti.bat:

@echo off
setlocal

set name=%cd%

set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%
set name=%name:*\=%

title=%name%

endlocal
Explanation of non-obvious things follows:
  • set name=%cd% gets name of working directory.
  • following collection of lines is my workaround for a loop that did not work for me well. If you can help me to get rid of this duplication (and limit to 10 subdirectories) I will be very glad.
  • set name=%name:*\=% removes text from variable up to the first backslash or it does nothing if there is no backlash.
  • setlocal, endlocal keep changes in variables private for script execution, changes are forgotten when it ends.
So when I open a new console to perform my building tasks I can write ti [ENTER] and the title is nicely renamed from original not very useful C:\WINDOWS\system32\cmd.exe to something like dao_testing.

IntelliJ Idea working directory hint

Added: September 29, 2008

Tags: hint idea

I was struggling with running our unit tests in Idea for some time. Problem was that we have many modules and some of our tests using files try to find them through working directory instead of classpath. So every time I needed to execute test/suite from different module I needed to change working directory of test to point to its own module.

Finally I was able to find great solution (I really do not understand why I did not try it sooner :-) ). Just open Run/Debug dialog, click to Edit Defaults and write $MODULE_DIR$ into Working directory: field.