Archive for the ‘java’ Category

Spring into kotlin: A short video presentation

December 15, 2018

If you heard about kotlin and have some knowledge about the spring framework you might enjoy this 30 min video presentation on infoq.com.

Mark Heckler discusses how Kotlin can be used to reduce boilerplate and increase code quality, showing how to begin incorporating Kotlin into an existing Spring application.

Springing into Kotlin: How to Make the Magic Even More Magical

Android Studio on Linux 64bit: Emulator Timeout Problem

May 21, 2017

As a reminder for myself and maybe as a help for others: If you try to start the android emulator via Android Studio and the console tells you only this:

WARN – run.EmulatorConnectionListener – Timed out after 300seconds waiting for emulator to come online.

Then maybe you have fix your problem by removing the libstdc++.so.6 provided by the Android Studio so it uses the system one. For example:

~/Android/Sdk/emulator/lib64/libstdc++$ mv libstdc++.so.6 libstdc++.so.6.bak

Source: Stack Overflow: Cannot launch emulator on Linux (Ubuntu 15.10)

 

Maven: Parent POM in repo, but Non-resolvable error

December 5, 2016

If you are using maven you may have been flabbergasted by an error like this

[ERROR] Non-resolvable parent POM: Failure to find at.test:test:pom:23 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 9, column 10

I had this error and was wondering why it was occurring? I had the parent artifact in my local repository. It was not missing. Maven did know this, because the log said

[DEBUG] Verifying availability of /home/stefon/.repository/at/test/test/23/test-23.pom from [central (http://repo.maven.apache.org/maven2, releases)] 

So if I have the parent POM file in my repository and maven knows about it? Why are we getting an error?

As the file is not available on central, Maven will (correctly in my opinion) fail the build as the build would be non-reproducible.
(Mailarchive Maven-Users)

So, what do we do if it is not possible to publish our parent pom artifact?

there is a CLI option that you can enabled in Maven 3.1.1 that tells Maven “I know what I am doing and don’t make that check this time” i.e.  –legacy-local-repository

In other words:

 mvn clean install --legacy-local-repository

Just remember: This is a hack and may break at any moment with a new maven version! There is an blog article where you can find other solutions for your problem

Howto convert HTML into plaintext

January 20, 2009
JEditorPane pane = new JEditorPane("text/html", html);
String plainText = pane.getDocument().getText(0, pane.getDocument().getLength());

Yes, you can use the Swing JEditorPane to convert HTML into plaintext. Weird but true.

Source: DerKoe

Sonar – open source project management tool

January 17, 2009

If you are managing a big java project and you use maven changes are high that you are running test coverage and code quality reports.
Analyzing this multitude of reports can be quite exhausting. At work we use Sonar, which uses data from a lot of maven reports (code coverage, pmd, …) and creates an overview on your project. AND it can be setup in about 20 minutes.

SONAR is a code quality management platform, dedicated to continuously analyze and measure technical quality, from the projects portfolio to the class method.

You can read here about the features of it. It even has a time machine to let you investigate the changes of your project over time.

A new approach to unit tests

October 26, 2008

There is an article on  the Legolas in Minas Tirith blog which is about Unit Testing. The posting state that Unit Testing (in the form of JUnit or TestNG) is kind of flawed because it tests implementations of an interface.
So if you create a new implementation of the interface, you have to create a new test.

So the suggestion is to talk something from Design By Contract and connect it with Unit Testing. So Unit Testing is concerned with testing the Contract definied by an interface. So every implementation has to fullfill the contract of the interface.

With TestedBy, tests declared on an interface (or a superclass) can be run upon all implementers to verify they’re respecting the behaviour and contract defined in the super type. IOW the API designer not only provides the interfaces, but also a set of test classes verifying expected behaviour. Then every implementer would supply its own implementation and run the tests provided by the API designer against its concrete classes to verify they are respecting not only type safety but also beahviour/contract safety for which the API was designed. TesteBy here invokes a test defined for an interface passing to test class a concrete instance of class implementing the interface under test.

More on this topic can be read in A new approach to unit tests.

How to handle java Exceptions?

July 11, 2008

Exceptions are difficult to handle. Java Exceptions aren’t different.
Elliotte Rusty Harold tries to remove the confusion.

Perhaps the continuing confusion over the difference between checked and runtime exceptions in Java is because we haven’t named them properly. Mosts texts and teachers, including myself, have traditionally focused on how and when you handle the exceptions (compile time or runtime) rather than on what causes each. I propose a modification, not in code, but in terminology and teaching. Specifically I think we should should start calling checked exceptions “external exceptions” and runtime exceptions “internal exceptions”.

After some examples and explanations he concludes

If the exception is caused by problems internal to the program, it’s a runtime exception. If it’s caused by problems external to the program, it’s a checked exception.

Source: The Cafes

Tapestry for Nonbelievers

May 20, 2008

InfoQ.com has an article explaining the benefits of using apache tapestry as an webframework for your projects.

In this article we are going to introduce you the version 5 of the framework. We will develop a simple Create/Read/Update/Delete application using Tapestry 5 and show a few of the productivity benefits provided by Tapestry.
We will describe different aspects of Tapestry applications, such as page navigation, dependency and resource injection, user input validation and application state management. You will also see how to use the Ajax functionality built in to Tapestry and how to create your own Ajax-capable components.

Source: InfoQ.com

Why should I care about OSGi

May 19, 2008

Adrian Colyer talks about OSGi and what benefits comes with using it.

Development time benefits

  • Strict development time (and runtime) enforcement of module boundaries
  • A service-oriented architecture that works for managing service dependencies between modules.
  • Better ability to structure development teams the way you want to
  • Faster team-based development
  • Faster testing cycles
  • Support for versioning as part of dependency management

Runtime benefits

  • Full information about the installed modules and their wiring is available at runtime – a level of insight operations teams have never had before
  • Isolate changes
  • Share dependencies
  • Use just the server facilities you need

All this assumptions are backed up with arguments in his article.

Source: SpringSource

OSGi for Beginners

May 9, 2008

If you are following tech related websites you may recognize the abbreviation OSGi. Every time I read about it I shows me that it may be “the next big thing”.

So knowing it and be prepared when everybody is talking about and thinking about to use it may be a good idea.
So the article OSGi for Beginners on theServerSide.com is coming at the right time.

OSGi is a framework for Java in which units of resources called bundles can be installed. Bundles can export services or run processes, and have their dependencies managed, such that a bundle can be expected to have its requirements managed by the container. Each bundle can also have its own internal classpath, so that it can serve as an independent unit, should that be desireable. All of this is standardized such that any valid OSGi bundle can theoretically be installed in any valid OSGi container.