Beiträge getagged mit Java
Perle IOLAN und RXTXcomm (Java) unter Linux
Für unser aktuelles Projekt verwenden wir eine Perle IOLAN-Box. Die Box stellt serielle Ports – in unserem Fall sind das zwei Stück – über Ethernet zur Verfügung.
Der Einsatzbereich ist z.B. nötig, wenn man GSM-Modems in abgeschirmten Räumen (Rechenzentren, Bunkern) betreiben will. Die IOLAN-Box bildet eine Bridge zwischen Seriell- und Ethernet ab. So lässt sich das GSM-Modem (Seriell) an die IOLAN-Box (Seriell) anschließen, die wiederum über Ethernet an das Netzwerk angebunden ist. Für Linux und Windows existieren passende Programme, die nun lokal wiederum die Verbindung über das Netzwerk als serielles Interface abbilden.
Gestern stieß ich bei der Einrichtung der lokalen Schnittstellen auf ein Problem: RXTXComm – das Java-Framework zur Kommunikation mit seriellen/parallelen Schnittstellen – listete beim Start die /dev/tx00*-Devices nicht auf. Die FAQ von RXTX weist daraufhin, dass man per
System.setProperty(“gnu.io.rxtx.SerialPorts”, portFileNames) zusätzliche Ports definieren kann. Der Lösungsansatz brachte kein Erfolg.
Zweite Idee war dann, dass ich – wie in der FAQ beschrieben – die tx*-Devices manuell in die RXTXCommDriver.java eintrage. Auch das war nicht von Erfolg gekrönt.
Let the ants feed the bird: ant-twitter, a Twitter task for Ant
Verfasst von Schakko unter Java, Open Source, Projekte am 18. November 2009
I have learned the last 5 day for business studies and was so bored that I really got happy when I saw the article about a Twitter-Maven-Plugin on entwickler.com yesterday morning.
We still use Ant as building system in our development team so I searched for an Ant task which enables Twitter support. As I did not found any plugin I started to write my own simple task called ant-twitter.
Features
- Support for URL shortening service bit.ly via bitlyj
- Support for messages more than 140 characters – the message will be splitted into two or more messages. A small source snippet is taken from jtwitter – thanks a lot guys!
- Open source – Apache license
- It is simple
Installation
I assume you have already installed Ant-1.70 (1.6x should work although) and configured your Ant working environment. I refer to $ANT_LIB$ which is a directory where your Ant installation can found further JARs (should be appended to your classpath).
- Download needed packages and extract them to $ANT_LIB$:
- bitlyj-1.0-snapshot
- twitter4j-2.0.10 – you have to extract all files in directory lib, too!
- json-lib-2.3 – needed by bitlyj
ant-twitter-1.0.zip (25.9 KiB, 152 hits)
- Create a file twitter4j.properties in your classpath ($ANT_LIB$) and paste the following code into it:
twitter4j.http.useSSL=true twitter4j.debug=false
Usage
After you have installed the needed dependencies and upset your configuration you have to edit your build.xml. Put the following taskdef in top of your build file:
<project name="TwitterTestTask" default="main" basedir="."> <taskdef name="twitter" classname="de.ecw.ant.twitter.AntTwitterTask"/>
You are now able to use the twitter task in form of
<twitter message="Hello World from Ant!" username="twitter-username" password="twitter-password" bitlyUsername="bitly-username" bitlyApiKey="bitly-key" enableBitly="false" />
ant-twitter has the following options:
- message (required, String): Your Twitter tweet
- username (required, String): Your Twitter screenname
- password (required, String): Your Twitter password
- bitlyUsername (optional, required if enableBitly=true, String): Your bit.ly username
- bitlyApiKey (optional, required if enableBitly=true, String): Your bit.ly API key
- enableBitly (optional, true|false): Enable bit.ly support
Interessante Links (Die besten Einzeiler, Analyse mit Traceroute, Closures and JVM)
Verfasst von Schakko unter Effizient arbeiten, Java, Linux am 23. Februar 2009
Hier ein paar interessante Links, die über das Wochenende in meinen Lieblings-Blogs aufgetaucht sind
- Command Line FU – Die besten Einzeller Einzeiler für die Kommandozeile (Linux)
- Analyse mit Traceroute
Bug unter Linux mit Java 1.5.0
Verfasst von Schakko unter Application Server, Java, Linux am 10. Februar 2009
Gestern war ich damit beschäftigt, unser Deployment-Tool im Server-Modus in einer Ubuntu-VM zu installieren. DT läuft als J2EE-Applikation und wurde von mir in einem Tomcat 6.0 unter Java 1.6 deployt. Die Kombination von Tomcat 6.0 und Java 1.6 führte aber -mal wieder aus unerfindlichen Gründen – dazu, dass weder die Logs unter /var/log/tomcat6 gefüllt wurden, noch mein eigenes DT-Log. Die Dateien wurden zwar angelegt, aber die Log-Messages wurden nicht geschrieben. Laut ps aux und /var/log/syslog lief Tomcat aber. Der Verdacht, dass die Festplatte vollgelaufen wäre, bestätigte sich nicht.
Ich führte also ein Downgrade auf Java 5 und Tomcat 5.5 durch. Nach dem Start des Tomcats bekam ich ein Segmentation Fault der Hotspot VM mit dem Status SIGBUS (0×7). Im Internet wurde ich dann im Bugtracker von Sun auch schnell fündig: Sobald das /tmp-Verzeichnis voll ist, schmiert die Hotspot VM ab. Der Fehler traf auf mein Problem genau zu, da ich vorher mit strace die Aufrufe der VM nachgegangen bin und diese nach dem Zugriff auf /tmp/hsperfdata abstürzte. Radikale Lösung war: rm -rf /tmp/*.
Spring Framework 2.5.6-1 und XBeans
Gegenwärtig bin ich dabei, unser Deployment-Tool (DT) um SOA-Features (SOA ist tot – es lebe SOA) anzureichern. Der Plan ist, dass die komplette Administration über SOAP geschieht.
Da ich DT als Projekt für das Testen von mir unbekannten Frameworks und Technologien sehe, habe ich mich für JAX-WS (Version 1.8) als Webservice-Provider und dem Spring Framework in der Version 2.5.6 entschieden. Christian Ullenboom – der Autor von Java ist auch eine Insel – hat in seinem Blog einen Artikel über die Verwendung genau dieser Framework-Kombination verfasst. Allerdings sind die benutzten Versionen unterschiedlich – das führte bei mir dazu, dass ich die Exception java.lang.NoClassDefFoundError: org/springframework/beans/factory/support/ReaderContext bekam.
Um es kurz zu machen: Die Spring-XBean Distribution in der Version 3.3.0 herunterladen, Spring Framework 2.5.6-1 einbinden und schon funktioniert es so, wie es soll.
Using BIRT and PHP without Zend Plaform
Verfasst von Schakko unter Arbeit, Java, Open Source, PHP, Publikationen am 24. April 2007
Oh well… my first blog entry in English, because I think this article is interesting for all the PHP developers out there – including non-German people
Every developer will reach the point generating reports for the running project. Making reports with Java oder .NET is relatively easy. Products like Crystal Reports (commercial) or BIRT (open source) support developers in designing and creating pleasant reports.
PHP can be extended with the function of BIRT with buying the Zend Platform. But in most cases the minority of people is able to buy this product. Zend Platform costs around 1000$ – 1500$ for a one year license.
Our development team had the problem of generating reports with PHP more than one time. In our last project we used FOP + XSL/XSLT from the Apache Foundation and triggered the report building by using exec() and command line.
The problem with FOP is that it is highly memory intensive and the building of XSLT templates is time consuming – if you do not have nice tools for that.
Last week I investigated and evaluated BIRT for using it in a J2EE/GWT-based application we are programming. The BIRT Designer is a nice tool for creating reports in HTML and/or PDF and we will (hopeley) include it in our project.
I demonstrated the results Christoph who was really amazed of it. Christoph said “Well… it would be so nice using BIRT with PHP for ZABOS (ZABOS is our SMS Alert System). But Zend Platform is sooo expensive.” (mimimi)
It was friday afternoon and nothing more was to do so I decided to look for reporting mechanisms in PHP. The results were… let’s say: poor
The next idea was triggering BIRT from command line via PHP exec()’s method. I wrote a wrapper class in Java, which could be used to start BIRT from command line (using java -jar de.ecw.birt.BIRTRunner –help).
After some minutes of coding and testing this class worked like a charme. I was happy, but I thought “Woah… It would be nice using Java directly from PHP”. I remembered that there was a PHP module called php_java which could access Java through the JNI (Java Native Interface). But all the comments on php.net said the old php_java module is more than deprecated and does not work. The newer commentator said that the php/Java-Bridge was a worth checking at. Hm… I read the documentation of the php/Java-Bridge and was enthusiastic: This was exactly what I needed.
I downloaded the latest release and was a little bit confused about the different files and JARs.
The solution is easy: Unpack the JavaBridge.war archive. The folder /java is needed in your PHP project path and includes all classes for connecting to the JavaBridge-server.
The file /WEB-INF/lib/JavaBridge.jar must be extracted to a directory of your choice (= $path-to-java-bridge). Please create inside this directory another directory called ‘lib’.
Your folder must look like this:
/java-bridge
JavaBridge.jar
/lib
Afterwards I started the server:
cd $path-to-java-bridge java.exe -Dphp.java.bridge.base=$path-to-java-bridge -jar JavaBridge.jar SERVLET:8080 6 php-java-brige.log
The log file did not show any error so I tried a simple “Hello world” in Java and PHP:
<?php
// index.php
require_once("java/Java.inc");
$aString = new Java("java.lang.String", "Hello world");
print $aString;
?>
Really nice: PHP connected to the local JavaBridge server. The JavaBridge instantiates a new String-object an called the toString() method. This was exactly what I needed for using php/Java-bridge with BIRT.
I refactored my own BIRTRunner class so that I just needed to call 4 methods and I got the desired result.
The appended .jar file must be extracted to the $path-to-java-bridge/lib, and you must restart the JavaBridge AND Apache. There seems to be an issue with UTF-8/JavaBridge/Apache.
My index.php had to be refactored too:
<?php
// index.php
// require JavaBridge interface
require_once("java/Java.inc");
// set encoding to UTF-8
java_set_file_encoding("UTF-8");
// remove try-/catch-block if not using PHP5
try
{
// where our reports are stored
$targetFile = "d:/result.html";
// ConcreteTask encapsulate the logic
$birtTask = new Java("de.ecw.birt.task.ConcreteTask");
// the home of your BIRT-runtime directory
$birtTask->setEngineHome('D:\Development\BIRT_Runtime\ReportEngine');
// the path of your BIRT report design
$birtTask->setReportPath('D:\Development\BIRT\workspace\CAPlan\user.rptdesign');
// create new render options
$htmlRenderOptions = new Java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$htmlRenderOptions->setOutputFileName($targetFile);
$birtTask->setRenderOption($htmlRenderOptions);
// run the BIRT task
$birtTask->run();
// get file content and print to browser
$content = file_get_contents($targetFile);
echo $content;
}
catch (JavaException $e)
{
print $e->getMessage();
}
?>
To my surprise it worked. I had not really expected it – but I was really able to use PHP and BIRT without buying Zend Platform.
There are so many possibilities and TODOs I want to mention:
* You can create the .rptdesign on-the-fly using Smarty
* You cold write a wrapper class on PHP side so it is much easier to create reports
* … to be continued
Sag was!