GWT 2.0 SVN Snapshots have stopped working with Eclipse GWT Plugin
I regularly follow the development of Google Web Toolkit 2.0 and I compile and use its SVN snapshots in my projects.
Recently, after doing the regular svn update to SVN revision 7229 (Last Changed Date: 2009-12-02 08:01:22 +0200 (Wed, 02 Dec 2009)), I discovered that, in GWT Plugin for Eclipse 3.5, regular “Web Application” configuration fails with message:
Unknown argument: -style
It looks like some breaking change.
Luckily, it is possible to launch and debug your GWT project without using GWT Eclipse plugin. Just create a regular “Java Application” launch configuration, set “Main Class” to com.google.gwt.dev.DevMode, at the “Arguments” section set “Program Arguments” to something like -codeServerPort 9997 -port 8888 -war war -startupUrl myproject.html foo.bar.MyProject. One more thing to do is adding your “src” folder to “User Entries” in “Classpath” section and you are ready to continue your development.
Java webapps and externalization of their configuration
One of the most annoying things, in my opinion, is application’s configuration management. Naturally, it depends on operating system and hardware environment, but the most frequently moving target is whether your app is running in development or production environment which forces you to change configuration files every time you copy your files to the production or beta-testing server.
Yes, I’ve previously written on automated build process where I mentioned config file generation from template, although in my particular case, I developed that build process for an existing application. For a new application, I wanted something cleaner.
As I’m writing this new web application in Java, my first idea was to make use of the existing J2EE standards, particularly, JNDI: just create my own configuration POJO class and store it in the servlet container (per-application scope) and reference it through some constant URL like java:comp/env/bean/ApplicationConfig.
I ran into two problems in no time:
- Servlet container (either Tomcat and Jetty), on its startup, threw
ClassNotFoundExceptionbecause it didn’t know anything about myApplicationConfigclass until my webapp context was loaded. That problem can be solved by copying that particular *.class file to the container’s class path, which then reveals next problem ClassCastExceptiongets thrown when assigning pointers to objects of seamingly identical class (cannot castfoo.bar.Applicationtofoo.bar.Application). Now that occurs because instances of these classes come from different class loaders, i.e., server and application.
That as kind of disappointing because I’ve been thinking that storing POJOs in JNDI is kind of easy, convenient and even recommended practice.
Eventually, I opted for a simpler way - a configuration file :), location of which is defined outside of application itself - a system property. I found it is easy to define in production environment as a -Dfoo.bar.config.location=... in JAVA_OPTS or similar environment variable. In development environment, I use Jetty Maven plugin which has systemProperties configuration argument.
My configuration class I designed as a singleton class, something like this:
public class ApplicationConfiguration {
private String foo;
private static ApplicationConfiguration instance;
private ApplicationConfiguration() {
}
public void getFoo() {
return foo;
}
void setFoo(String foo) {
this.foo = foo;
}
public static ApplicationConfiguration get() throws Exception {
if (instance == null) {
String configLocation = System.getProperty("foo.bar.app.config.location");
Properties properties = new Properties();
properties.load(new FileInputStream(configLocation));
instance = new ApplicationConfiguration();
instance.setFoo(properties.getProperty("foo.bar.property"));
}
return instance;
}
}
Now, I could reference my application’s configuration from anywhere using ApplicationConfiguration.get() method.
The last problem I had to solve was how to inject this configuration POJO in my Spring beans. Luckily, I could use the static factory-method bean tag attribute, something like this:
<bean id="appService" class="foo.bar.ApplicationService">
<property name="configuration">
<bean class="foo.bar.ApplicationConfiguration" factory-method="get"/>
</property>
</bean>
That basically satisfied my requirements and saved me a lot of hassle with re-deploying and editing config files in different environments.
Youtube and Copyright Issues in Latvia
In Latvian blogosphere, a new scandal has emerged after local self-proclaimed and unfortunately government-authorized “copyright defender” AKKA-LAA had sent emails to approx. 500 blog website owners informing them that music videos from Youtube embedded in their websites are illegal.
Website owners claim that they don’t have actual files on their web servers, they are hosted by Youtube, AKKA-LAA in response keeps arguing that effectively user watches a copyrighted video while visiting particular website. According to them, legal solution would be not using Youtube’s offered embedding tags but posting the clickable link to Youtube’s website instead. The most interesting claim from AKKA/LAA representative is that (rephrasing) “Watching Youtube’s videos in Latvia is illegal and AKKA/LAA has initiated negotiaton with Youtube on legalizing their activities in territory of Latvia”. More on this here (in Latvian).
I agree that there’s many legal work to be done concerning copyright in Internet but I’m really wandering where do people live when they claim that “Internet is relatively new type of media”, that’s really hilarious… well, if not scary. And here’s why:
If I understand correctly, Youtube’s already paying artists fees for hosting their videos. If I was Youtube executive, I wouldn’t listen to some AKKA/LAA from some country with 2.3M population claiming that my company’s activities there are illegal and, God forbid, I have to pay them more money for allowing users to use my service. I would just restrict access to Youtube’s servers from that country’s IP addresses and that’s all.
Is this what AKKA/LAA really wants?
Project Build Process: First Experience
Recently, I stumbled upon Joel Spolsky’s Test which measures the quality of a software development team. We might argue whether the results of these tests are important indicators or not, but one cannot deny that these 12 questions actually suggest good development practice.
One really important thing in my (and my organization’s) development practice was missing - a one step build - see #2 in the Joel’s test. Digging a bit deeper, one can realize that it is a dependency for #3 as well.
So what?
Let’s think about the “build” process that consists of multiple manual steps. It basically involves compiling source files (not the case of interpreted languages - PHP, for instance), copying files somewhere (on local disk or remote server), adjusting configuration files. That’s the minimum. In case files need to be writable by the application/web server, you’d have to chmod your files/directories as well. Quite a mess isn’t it? If you have to do this for just one server - say production - you’re lucky but that scenario is very, very unrealistic. You might want to deploy your application to some test environment - like virtual machine or other server etc. And of course, we cannot neglect the fact that people make mistakes - typos, forget things etc. Now THAT is really a mess.
Cleaning up the mess
I found two most likely scenarios of deploying a web application:
- Deployment or re-deployment to production.
- Checking out the source from the SCM system
- Compilation if needed
- Generation of configuration files (important directories, database access etc.) from some given template
- Actual file copying to the server
- Changing necessary permissions, invoking other commands on the production server
- Deployment or re-deployment for testing
- Compilation (if needed)
- Re-generation of configuration files for the same purpose that in 1.3
- File copying to the server
Both scenarios assume that necessary environment (databases, virtual hosts) are already configured. That is a one-time job and should be documented somewhere, configuration file template, for instance.
I started to roll out my own script in Python but then I realized that this is a right job for the Apache Ant. It doesn’t matter whether your project is Java or not, it’s really a swiss army knife for everything. Surely, using Ant you introduce another two dependencies to your build process - Java RE and Ant it self.
I’m not going to post my full build.xml file here, I’ll just mention a few issues I had to solve.
- Ant doesn’t have any stock instruments that check out your source code. For SVN (my case) there’s the corresponding external Ant task available.
- I don’t use FTP for copying files to the server, neither mount any network filesystems. I use SFTP/SSH/SCP to copy files and didn’t want that to change. Ant has optional scp and sshexec tasks but they depend on a JSch library that is a SSH2 implementation in pure Java. By the way, one gotcha here: I found that some versions of JSch library do not work - the execution process just stalls and that’s all. I can confirm though that scp and sshexec tasks work with JSch v. 0.1.29.
- For config file generation, I opted for FMPP which is based on Freemarker template engine. My config file templates are actually Freemarker templates. This library has an Ant task, hence one can fill his/her template with data directly from ant build file properties.
- For file copying, I found a huge speed boost when using rsync together with ssh. Actually without rsync testing, i.e., regular (at most 5 minute interval) re-deployment for testing purposes wouldn’t be possible. Rsync copies just those files that have been actually changed, not all of them. Ant does not have any “rsync” tasks, neither 3rd-party or optional, so the only solution I found was using ant core’s exec task. You will have to overcome a few issues though:
- You make rsync to use ssh by using the rsync’s
-e sshswitch. By default, it makes the process asking for your remote users’ password. Since processes launched by ant are in the non-interactive mode, there’s no way how you can enter this password. Luckily, there is a way how to log in to the remote system via ssh without asking a password - check out some tutorials, this for instance. - RSync is not available on Windows systems. In that case, you have to resort to Cygwin. It also involves configuring your file system paths so that cygwin can see them - e.g. adding
/cygwin/c/prefix instead of regularC:/. Otherwise, rsync from exec task will complain that it won’t copy files between two remote filesystems - apparently, colon afterCfor rsync is confusing. That is achievable from ant - I used condition and replaceregexp tasks
- You make rsync to use ssh by using the rsync’s
- I don’t keep actual config files in SCM any more. Instead, I keep config file templates and I edit only them. Even more, I added
svn:ignoreto all the generated files. And forget about editing config files manually. - You might consider re-structuring your app so that server-writable directories are outside the directory you deploy your application, i.e., outside the htdocs or public_html directory. It is a matter of environment configuration to make those files reachable by URL from outside directly if needed - see the Alias directive in case of Apache HTTPD web server.
Final notes
I still haven’t made such a build for database, since it does not change so often and its deployment (at least in my case) is very easy.
If you haven’t created your one-step (or as-few-step-as-you-can) build then I urge you to do so. It took me a few days but immediately after that I felt how rewarding it is.
Using custom widgets in Glade3
While playing around GNOME and Gtk development, it became interesting to me how to add custom widgets that are not in Gtk+ base library, GtkSourceView, for instance. I discovered that Glade’s Custom Widget is obsolete.
Naturally, for new development, one does not use obsolete features. I searched Google to find out what’s offered in place of Custom Widget but could not find any sane answer… well, until I found this mailing list message.
You just don’t add any custom widgets in design-time in Glade. Instead, you just instantiate your widget and add it to some placeholder, like GtkPaned, for example.
In C#/Mono it looks like that:
using GtkSourceView;
public class Foo
{
[Glade.Widget]
private Gtk.Paned paned;
public Foo()
{
//Initialization, Autoconnect, etc
//....
SourceLanguagesManager manager = new SourceLanguagesManager();
SourceLanguage language = manager.GetLanguageFromMimeType("application/x-perl");
buffer = new SourceBuffer(language);
buffer.Highlight = true;
paned.Add1(new SourceView(buffer));
}
}
Of course, you only need private member if you’re going to reference your container (Gtk.Paned in this case) instance from somewhere else in your code. Otherwise, just use Glade.XML’s GetWidget().
Glade3 has been around for a while, so I’m wandering why there’s so little information on this. Who knows, maybe it’s just too obvious.
Initial Import
This is the first post created by myself just to test some of the basic Wordpress features
