[Suiviobsmer-commits] r102 - in trunk: . suiviobsmer-ui suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/war
Author: fdesbois Date: 2009-12-07 17:59:25 +0000 (Mon, 07 Dec 2009) New Revision: 102 Added: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/war/ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/war/SuiviObsmerWarLauncher.java Modified: trunk/pom.xml trunk/suiviobsmer-ui/pom.xml Log: - Add winstone dependency to have embedded application server in war file - Use topia and eugene last versions tagged Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-12-07 16:19:56 UTC (rev 101) +++ trunk/pom.xml 2009-12-07 17:59:25 UTC (rev 102) @@ -110,6 +110,11 @@ <artifactId>h2</artifactId> <version>1.1.114</version> </dependency> + <dependency> + <groupId>org.jvnet.hudson.winstone</groupId> + <artifactId>winstone</artifactId> + <version>0.9.10-hudson-16</version> + </dependency> <!-- base postgres --> <!--dependency> @@ -230,10 +235,10 @@ <!-- libraries version --> <nuitonutils.version>1.1.1</nuitonutils.version> - <topia.version>2.3.0-beta-SNAPSHOT</topia.version> + <topia.version>2.3.0-beta-1</topia.version> <license.version>2.0.0</license.version> <helper.version>1.1.0</helper.version> - <eugene.version>2.0.0-beta-SNAPSHOT</eugene.version> + <eugene.version>2.0.0-beta-1</eugene.version> <tapestry.version>5.1.0.5</tapestry.version> <!-- default license to use --> Modified: trunk/suiviobsmer-ui/pom.xml =================================================================== --- trunk/suiviobsmer-ui/pom.xml 2009-12-07 16:19:56 UTC (rev 101) +++ trunk/suiviobsmer-ui/pom.xml 2009-12-07 17:59:25 UTC (rev 102) @@ -60,6 +60,11 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> + <dependency> + <groupId>org.jvnet.hudson.winstone</groupId> + <artifactId>winstone</artifactId> + <scope>provided</scope> + </dependency> </dependencies> @@ -82,7 +87,41 @@ <!-- ************************************************************* --> <!-- *** Build Environment ************************************** --> <!-- ************************************************************* --> + <build> + <!-- call result war : suiviobsmer-xxx.war --> + <finalName>suiviobsmer-${project.version}</finalName> + <!-- Add main class into war to make it executable --> + <plugins> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <version>2.1-beta-1</version> + <configuration> + <webResources> + <resource> + <directory>${basedir}/target/classes</directory> + <includes> + <include>**/war/*</include> + </includes> + </resource> + </webResources> + <!-- for putting Main-Class into war --> + <archive> + <manifest> + <mainClass>fr.ifremer.suiviobsmer.ui.war.SuiviObsmerWarLauncher</mainClass> + </manifest> + </archive> + <overlays> + <overlay> + <groupId>org.jvnet.hudson.winstone</groupId> + <artifactId>winstone</artifactId> + <type>jar</type> + </overlay> + </overlays> + </configuration> + </plugin> + </plugins> + </build> <scm> <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk</connection> Added: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/war/SuiviObsmerWarLauncher.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/war/SuiviObsmerWarLauncher.java (rev 0) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/war/SuiviObsmerWarLauncher.java 2009-12-07 17:59:25 UTC (rev 102) @@ -0,0 +1,94 @@ +/* *##% + * Copyright (C) 2009 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package fr.ifremer.suiviobsmer.ui.war; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.net.JarURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Map; + +import winstone.Launcher; + +/** + * War main class launcher. + * + * Based on winstone micro container. + * + * To use it : + * java -jar pollen-xxx.war + * + * @author chatellier + * @version $Revision: 2778 $ + * + * Last update : $Date: 2009-10-12 14:25:49 +0200 (lun. 12 oct. 2009) $ + * By : $Author$ + */ +public class SuiviObsmerWarLauncher { + + /** + * Main method (used by war in manifest). + * + * @param args args + * @throws IOException + */ + public static void main(String[] args) throws IOException, URISyntaxException { + + System.out.println("Starting suiviobsmer embedded mode..."); + + String fqnLauncherFile = SuiviObsmerWarLauncher.class.getName().replaceAll("\\.", "/") + ".class"; + System.out.println("Search for launcher class : " + fqnLauncherFile); + + URL classFile = SuiviObsmerWarLauncher.class.getClassLoader().getResource(fqnLauncherFile); + System.out.println(" - using classFile : " + classFile); + + // strange following line seams also work for jnlp launch + File me = new File(((JarURLConnection) classFile.openConnection()).getJarFile().getName()); + System.out.println(" - using warfile file : " + me); + + // hashArgs map, initialized with command line args + Map<String, String> hashArgs = Launcher.getArgsFromCommandLine(args); + + hashArgs.put("warfile", me.getAbsolutePath()); // or any other command line args, eg port + + System.out.println(" - using args : " + hashArgs); + + Launcher.initLogger(hashArgs); + Launcher winstone = new Launcher(hashArgs); // spawns threads, so your application doesn't block + + int port = 8080; + String configPort = hashArgs.get("httpPort"); + if (configPort != null && !configPort.isEmpty()) { + try { + port = Integer.parseInt(configPort); + } + catch(NumberFormatException e) { + e.printStackTrace(); + } + } + Desktop desktop = Desktop.getDesktop(); + if (desktop.isSupported(Desktop.Action.BROWSE)) { + System.out.println("Opening browser at " + new URI("http://localhost:" + port)); + desktop.browse(new URI("http://localhost:" + port)); + } + } +}
participants (1)
-
fdesbois@users.labs.libre-entreprise.org