Spring 3.0 is final

16 Dec
2009

As Jurgen Hoeller posted today, Spring 3.0 is final!

I will check it out as soon as possible 🙂

 

Especially the SEO guys will find this one interesting: Google seems to started its Twitter integration as can be seen here:

Google Twitter Results

 

 

 

 

 

 

 

 

 

 

If you trying to migrate a legacy PHP application which still uses PEAR::DB to Quercus with PostgreSQL and JDBC-Connection Pools accessible through JNDI, this may come handy for you!

1. Create your Datasource e.g. in Glassfish v3’s admin console… I named mine jdbc/postgresDS

2. copy the file pgsqljndi.php to /usr/share/php/DB/pgsqljndi.php (or wherever you include your PEAR stuff from..)

3. change the database connection creation part of your script to this:

1
2
3
4
5
$db = & DB::connect("pgsqljndi://java:comp/env/jdbc/postgresDS");
if(DB::isError($db))
{
// error handling
}

4. remove stuff like this from your scripts

1
$db->query("SET NAMES 'utf-8'; ");

Your database connection with PEAR::DB, Quercus, PostgreSQL, JDBC + JNDI should work now!

Paul Sterk just announced the availability of the final version of Glassfish v3!

I just tried it out and it really rocks! Download, extract, start domain, running!
Even PHP Applications are easily possible: I will look further into this this weekend!

Engaged in Social-PM

10 Dec
2009

Since today, I’m a commiter in Scrumshark – the Social Project Management Tool.

One of my student groups in Advanced Software Engineering already are using this tool and I will try to extend it with some nice and helpful features.

Because I’m still sometimes doing some PHP-Coding, I wanted to get started with Maven for PHP, however, I ran into various problems with the way it was described on their webpage.

Unfortunately, also the mailing list did not respond to my mails, so I had to dig into the source alone.

The problem I had was, that although I added the profile-php-maven to my settings.xml, the archetypes where not recognized, resulting in an error-message like this, when trying to create a new project:

1
2
3
mvn archetype:generate -DarchetypeGroupId=org.phpmaven -
DarchetypeArtifactId=php5-lib-archetype -DarchetypeVersion=1.0 -
DgroupId=org.sample -DartifactId=my-app
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO]
------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:generate] (aggregator-style)
[INFO]
------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class =>
'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate]
[WARNING] No archetype repository found. Falling back to central
repository (http://repo1.maven.org/maven2).
[WARNING] Use -DarchetypeRepository= if archetype's
repository is elsewhere.
Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.0/php...
org.apache.maven.archetype.downloader.DownloadNotFoundException:
Requested download does not exist.
        at org.apache.maven.archetype.downloader.DefaultDownloader.download
(DefaultDownloader.java:62)
        at
org.apache.maven.archetype.common.DefaultArchetypeArtifactManager.exists
(DefaultArchetypeArtifactManager.java:310)
        at
org.apache.maven.archetype.ui.DefaultArchetypeGenerationConfigurator.configureArchetype
(DefaultArchetypeGenerationConfigurator.java:103)
        at
org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute
(CreateProjectFromArchetypeMojo.java:168)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo
(DefaultPluginManager.java:453)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals
(DefaultLifecycleExecutor.java:559)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal
(DefaultLifecycleExecutor.java:513)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal
(DefaultLifecycleExecutor.java:483)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures
(DefaultLifecycleExecutor.java:331)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments
(DefaultLifecycleExecutor.java:228)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute
(DefaultLifecycleExecutor.java:142)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:301)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:
315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:
430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by:
org.apache.maven.artifact.resolver.ArtifactNotFoundException: Unable
to locate resource in repository

Try downloading the file manually from the project website.

Then, install it using the command:
    mvn install:install-file -DgroupId=org.phpmaven -DartifactId=php5-
lib-archetype -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file

Alternatively, if you host your own repository you can deploy the file
there:
    mvn deploy:deploy-file -DgroupId=org.phpmaven -DartifactId=php5-
lib-archetype -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=
[url] -DrepositoryId=[id]

  org.phpmaven:php5-lib-archetype:jar:1.0

from the specified remote repositories:
  php5-lib-archetype-repo (http://repo1.maven.org/maven2)

        at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve
(DefaultArtifactResolver.java:212)
        at
org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveAlways
(DefaultArtifactResolver.java:80)
        at org.apache.maven.archetype.downloader.DefaultDownloader.download
(DefaultDownloader.java:54)
        ... 21 more
Caused by: org.apache.maven.wagon.ResourceDoesNotExistException:
Unable to locate resource in repository
        at
org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputData
(LightweightHttpWagon.java:100)
        at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:68)
        at org.apache.maven.artifact.manager.DefaultWagonManager.getRemoteFile
(DefaultWagonManager.java:475)
        at org.apache.maven.artifact.manager.DefaultWagonManager.getArtifact
(DefaultWagonManager.java:355)
        at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve
(DefaultArtifactResolver.java:196)
        ... 23 more
Caused by: java.io.FileNotFoundException:
http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.0/php...
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream
(HttpURLConnection.java:1311)
        at
org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputData
(LightweightHttpWagon.java:83)
        ... 27 more
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] The desired archetype does not exist (org.phpmaven:php5-lib-
archetype:1.0)

[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Mon Dec 07 02:15:42 CET 2009
[INFO] Final Memory: 16M/288M
[INFO]
------------------------------------------------------------------------ 

So.. maven does not recognize my profile, even not after upgrading to maven 2.2…. So I did checkout the source, and compiled the stuff myself:

1
2
3
svn checkout http://svn.key-tec.de/php-maven/trunk/ 
 
cd trunk/org.phpmaven.multimaster/

however, trying to build the project was not successfull because of miss-spelled directories and outdated dependencies

1
 mvn clean compile install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: unknown

Reason: Could not find the model file '/home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin'. for project unknown


[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Could not find the model file '/home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin'. for project unknown
	at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:404)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:272)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
	at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
	at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.project.ProjectBuildingException: Could not find the model file '/home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin'. for project unknown
	at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1575)
	at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:506)
	at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200)
	at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:604)
	at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:487)
	at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:560)
	at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:391)
	... 12 more
Caused by: java.io.FileNotFoundException: /home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin (No such file or directory)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.(FileInputStream.java:106)
	at hidden.org.codehaus.plexus.util.xml.XmlReader.(XmlReader.java:124)
	at hidden.org.codehaus.plexus.util.xml.XmlStreamReader.(XmlStreamReader.java:67)
	at hidden.org.codehaus.plexus.util.ReaderFactory.newXmlReader(ReaderFactory.java:118)
	at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1570)
	... 18 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Wed Dec 09 19:22:46 CET 2009
[INFO] Final Memory: 3M/73M
[INFO] ------------------------------------------------------------------------

I fixed those with two small + simple commands:

1
2
3
svn mv maven-php-plugin org.phpmaven.plugin # rename directory
# replace outdated wagon-ftp dependency
for i in `find . -iname 'pom.xml' | grep -v svn`; do sed 's/1.0-20080208/1.0-beta-6/g' $i > ${i}_xx ; mv ${i}_xx $i; done

after this, a simple

1
mvn install

did the trick for me.

I'm now creating new php-maven projects like this:

1
mvn archetype:generate -DarchetypeGroupId=org.phpmaven -DarchetypeArtifactId=php5-lib-archetype -DarchetypeVersion=1.1-SNAPSHOT -DgroupId=com.dominikdorn -DartifactId=my-example-app
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate {execution: default-cli}]
[WARNING] No archetype repository found. Falling back to central repository (http://repo1.maven.org/maven2). 
[WARNING] Use -DarchetypeRepository= if archetype's repository is elsewhere.
[INFO] snapshot org.phpmaven:php5-lib-archetype:1.1-SNAPSHOT: checking for updates from php5-lib-archetype-repo
Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar
[INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar
[INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar
[INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2)
Define value for version: : 1.0-SNAPSHOT
Define value for package: : com.dominikdorn.php-maven-example-app
Confirm properties configuration:
groupId: com.dominikdorn
artifactId: my-example-app
version: 1.0-SNAPSHOT
package: com.dominikdorn.php-maven-example-app
 Y: : Y
Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar
[INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar
[INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar
[INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2)
[WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/src/test/php/apptest.php [line 6,column 9] : $app is not a valid reference.
[WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/src/test/php/apptest.php [line 7,column 9] : $this- is not a valid reference.
[WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/src/test/php/apptest.php [line 7,column 42] : $app- is not a valid reference.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 29 seconds
[INFO] Finished at: Wed Dec 09 19:54:29 CET 2009
[INFO] Final Memory: 15M/166M
[INFO] ------------------------------------------------------------------------

It still does not find the dependencies, but at least it creates my project.

after fixing a issue with the auto-generated php-unit test, I can package my lib with this

1
mvn clean compile package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Sample PHP 5 library project
[INFO]    task-segment: [clean, compile, package]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory /tmp/test/test3/my-example-app/target
[INFO] [plugin:descriptor {execution: default-descriptor}]
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/test/test3/my-example-app/src/main/resources
[INFO] [php:php-validate {execution: default-php-validate}]
[INFO] [plugin:descriptor {execution: default-descriptor}]
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/test/test3/my-example-app/src/main/resources
[INFO] [php:php-validate {execution: default-php-validate}]
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/test/test3/my-example-app/src/test/resources
[INFO] [php:phpunit {execution: default-phpunit}]
[INFO] Surefire report directory: /tmp/test/test3/my-example-app/target/surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
apptest.php
Running AppTest
Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.001249

Results :

Tests run: 1, Failures: 0, Errors: 0

[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: /tmp/test/test3/my-example-app/target/my-example-app-1.0.jar
[INFO] [plugin:addPluginArtifactMetadata {execution: default-addPluginArtifactMetadata}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Wed Dec 09 20:04:51 CET 2009
[INFO] Final Memory: 27M/294M
[INFO] ------------------------------------------------------------------------

I'm in contact with Christian Widemann from Key-Tec to resolve the outstanding problems.

As Cagatay Civici recently posted, PrimeFaces hit the 1.0 Release Candidate!
Now its just a matter of days till 2.0 RC will be out, officially bringing PrimeFaces to JSF2!

Also they changed their namespace to org.primefaces meaning a new PrimeFaces project website will probably be online soon 🙂

If you’re trying out JavaMail with JavaEE (6) on Glassfish and get a ClassCastException like these

SEVERE: java.lang.ClassCastException: com.sun.enterprise.deployment.MailConfiguration cannot be cast to javax.mail.Session
javax.faces.el.EvaluationException: java.lang.ClassCastException: com.sun.enterprise.deployment.MailConfiguration cannot be cast to javax.mail.Session
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
        at javax.faces.component.UICommand.broadcast(UICommand.java:315)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:774)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1266)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:310)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1522)
...

when trying to inject the Mail-Session into your bean, try to do it the following way

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@ManagedBean(name = "registrationController")
public class RegistrationController {
 
@EJB
RegistrationServiceImpl registrationService;
 
@Resource(type = Session.class, name = "mail/projectMailSession", mappedName = "mail/projectMail")
Session mailSession;
 
private Member member = new Member();
 
....
 
private void sendRegistrationEmail(String activationCode) {
try
{
Message msg = new MimeMessage(this.mailSession);
msg.setSubject("Project X: Activation needed! ");
msg.setSentDate(new Date());
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(member.getEmailAddress(), false));
msg.setText("Welcome at Project X! \n" +
"Aktivierungscode: "+ activationCode + "\n\n bis bald!");
Transport.send(msg);
}
catch (MessagingException e)
{   e.printStackTrace();  }
}

The important part is bold printed: You have to

  1. inject the mail-session with the @Resource annotation,
  2. specify the class you want (type = Session.class),
  3. specify an alias for the jndi-name with this object ( here “mail/projectMailSession” )
  4. and specify the jndi name you used to specify the mail-session in the administration backend (I used “mail/projectMail”).

I’ve found the missing bits on this thread
http://old.nabble.com/Problem-on-configuring-Java-Mail-Session-td15955905.html

If you, like me, like to try out Glassfish v3 with its build in support for JavaEE6 and JSF 2, don’t even try to use the Glassfish v3 Preview Edition available on the Glassfish website.
Instead, use one of the nightly builds
http://download.java.net/glassfish/v3/nightly/
You will save yourself a lot of headaches.

As Lincoln Baxter posted recently in the PrettyFaces-Blog, the upcomming PrettyFaces 2.0.3 will include support for JSF-Validators within PrettyFaces, allowing to reuse the already existing Validators infrastructure for Pretty URL Mapping (SEO Stuff etc.)

Nice one Lincoln!

top