Pages
Mikael Ståldal
Software projects
Categories
Archives
- May 2023
- April 2023
- February 2023
- November 2022
- July 2019
- June 2016
- February 2016
- August 2015
- July 2015
- June 2015
- May 2015
- December 2014
- October 2014
- June 2014
- March 2014
- December 2013
- October 2013
- August 2013
- January 2013
- August 2012
- July 2012
- January 2012
- December 2011
- November 2011
- October 2011
- July 2011
- May 2011
- April 2011
- November 2010
- August 2010
- June 2010
- April 2010
- November 2009
- September 2009
- August 2009
- July 2009
- April 2009
- January 2009
- December 2008
- July 2008
- October 2007
- May 2007
- March 2007
- September 2006
- May 2006
Category Archives: Java
How to capture log events in tests with Log4j 2
Sometimes you want to verify that your program actually logs what it is supposed to be logging. When using Apache Log4j 2 as logging framework, it can be done like this: Include this dependency (for Maven, adjust appropriately for other … Continue reading
Posted in Java
Comments Off on How to capture log events in tests with Log4j 2
How to run exec-maven-plugin only if a file is not up-to-date
In my Maven build, I use exec-maven-plugin to run an external tool for Java code generation. In this case the flatbuffers compiler (flatc). By default, flatc always runs, so you always get a new .java file. This will always trigger … Continue reading
Posted in Java, maven, programming
Comments Off on How to run exec-maven-plugin only if a file is not up-to-date
Objects vs. data structures
Several popular statically typed programming languages, including C++, Java and C#, have a serious design flaw. They make no useful distinction between objects in the OOP sense and plain data structures. A plain data structure should only be a dumb … Continue reading
Posted in Java, programming
2 Comments
Typesafe’s Reactive Straw man
In their quest to promote Reactive, Typesafe is beating up a straw man by portraying blocking I/O in a particularly stupid way which is rarely (if ever) done in practice. In a recent webinar, I found this slide which suggests … Continue reading
Create a self-contained .jar file with Maven
If you want to create a self-contained .jar file, with all library dependencies included, you can do it with Maven. Include this in your pom.xml: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <mainClass>com.yourcompany.youapp.Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> … Continue reading
Posted in Java
Comments Off on Create a self-contained .jar file with Maven
Running Jetty as a service in Ubuntu Linix
Jetty is a popular open source Java application server. In order to run it as a service on a Linux server, they recommend using a horribly overcomplicated and quite fragile script. In Ubuntu server, there is a better way. Leverage … Continue reading
Don’t use large BLOBs in MySQL from Java
The MySQL database can store large chunks of binary data (up to 1 GB) using the BLOB data types. However, this does not work well if you access the MySQL database from Java (or any other JVM based language) using … Continue reading
Posted in database, Java
3 Comments
Don’t use PipedOutputStream on Android
I was using java.io.PipedOutputStream in an Android app. The app performed horribly bad. After doing some profiling, it turned out that the call to PipedOutputStream.write(byte[]) that was really slow. After digging into the Android source code, I discovered that PipedOutputStream.write(byte[]) … Continue reading
Posted in Android, Java
2 Comments
Using an embedded SQL database in Java web application
You have a Java web application needing a relational SQL database. According to JavaEE conventions, you declare the DataSource in web.xml: <resource-ref> <res-ref-name>jdbc/DS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> and then fetch it in code with (DataSource)new InitialContext().lookup(“java:comp/env/jdbc/DS”). Using Maven, Jetty and HSQLDB, … Continue reading
Posted in Java, JavaEE, web
3 Comments
Web application frameworks in Java
When you know which type of web application you are to develop, it’s time to have a look at some possible choices. I have tried to categorize some modern and popular web application frameworks in Java. Simple server driven MVC … Continue reading