Thursday, August 23, 2012

install and run an app on multiple devices with a single click under eclipse


If you using eclipse, just do below:
  1. open 'project properties' dialog.
  2. under 'Run/Debug settings', select your project and edit.
  3. another dialog should pop up, select 'target' tab, select 'Launch on all compatible devics/AVD's '.
  4. Apply and you should get all of devices install when Run/Debug.

Wednesday, August 22, 2012

Mass convert CR2 file to JPEG with Ubuntu


  1. apt-get install ufraw
  2. cd <dir of cr2>
  3. for i in *.CR2; do ufraw-batch $i --out-type=jpeg --output $i.jpg; done;

Thursday, August 16, 2012

Add new struts2 maven project in eclipse

1. Click File > New > Project... 
2. New Project will be prompted. Choose Maven > Maven Project. Click Next.
3. New Maven Project will be prompted. Click next.
4. Choose Nexus Indexer for Catalog. highlight maven-archetype-webapp(Artifact Id) and click next.
5. Fill in the Group Id, Artifact Id, version and click Finish.
6. Set the tools.jar dependence in your pom.xml. 

Add

 
<profiles>
      <profile>
          <id>default-tools.jar</id>
          <activation>
              <property>
                  <name>java.vendor</name>
                  <value>Sun Microsystems Inc.</value>
              </property>
          </activation>
          <dependencies>
              <dependency>
                  <groupId>com.sun</groupId>
                  <artifactId>tools</artifactId>
                  <version>1.5.0</version>
                  <scope>system</scope>
                  <systemPath>C:/Program Files/Java/jdk1.6.0_23/lib/tools.jar</systemPath>
              </dependency>
          </dependencies>
      </profile>
  </profiles>

This will solve the Missing artifact com.sun:tools:jar:1.5.0:system problem.

7. Add strut2
There are 2 ways to do it:

a. Right click the source folder, Maven > Add Dependency. Type struts2-core. Then, highlight the org.apache.struts struts2-core and click ok.

b. Add below in pom.xml

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.2.1.1</version>
    </dependency>

8. Add log4j and javassist dependencies.
<dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.2.1.1</version>
    </dependency>
  </dependencies>

** log4j is encouraged to be manually added to prevent Missing artifact log4j:log4j:bundle:1.2.16:compile

** Final pom.xml attached on below

9. Right click on the project: Run as > Maven install. This will build war file in the target folder of your project. 

10. Deploy the war file.

[attached]

ClassNotFoundException when Maven2 project on Tomcat 6 from with Eclipse

Start Dynamic web project with M2Eclipse, Maven2, Eclipse.

SEVERE: Servlet /CommunityWebServer threw load() exception
java.lang.ClassNotFoundException: com.cnx.community.servlet.HttpTransportServices
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1671)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)



Solution:
1. Delete the project from workspace.
2. Delete .project and .classpath from project folder
3. Make sure Maven Integeration for WTP (optional) is install, else install it from 
      http://m2eclipse.sonatype.org/sites/m2e-extras

4. Import the project again as Maven project.


End.

Webapps with Eclipse and Maven (maven-war-plugin)


Webapps with Eclipse and Maven (maven-war-plugin)


Web applications created by the Eclipse IDE contains an annoying folder WebContent to host the web resources and deployment descriptors. Quite natural for Eclipse users, this feature ignores the Maven convention and force the developers to hack the pom files in order to get the project up and running in Eclipse. In this aspect, Eclipse if far behind the other IDEs regarding Maven support, even if you consider the very good M2Eclipse plugin. So, for you lazy Christmas hackers, here it is a solution for the Maven integration problems in Eclipse based on the maven-war-plugin.
ERRATA: please use the WTP plugin instead of changing the project structure.  I figured out the wtp plugin after writting this blog, so I suggest you to check just the 1st and the 3th steps of the below instructions. I kept the original blog information in case you really need or want to change the project structure.
  1. Create a Web Project in Eclipse: right-click on the Project Explorer > New > Project > Web \ Dynamic Web Project
  2. Create a pom.xml file in the project root folder, with the following content:
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.cejug</groupId>
     <artifactId>webapp-test</artifactId>
     <packaging>war</packaging>
     <version>1.0-SNAPSHOT</version>
     <name>webapp-test Maven Webapp</name>
     <url>http://maven.apache.org</url>
     <repositories>
      <repository>
       <id>maven2-repository.dev.java.net</id>
       <name>Java.net Repository for Maven</name>
       <url>http://download.java.net/maven/2</url>
      </repository>
     </repositories>
    
     <build>
      <finalName>${project.name}</finalName>
      <plugins>
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
         <webResources>
          <resource>
           <directory>$/WebContent</directory>
          </resource>
         </webResources>
         <warSourceDirectory>WebContent</warSourceDirectory>
         <warSourceExcludes>WebContent/WEB-INF/lib/*.jar</warSourceExcludes>
         <archiveClasses>false</archiveClasses>
         <archive>
          <manifest>
           <addClasspath>true</addClasspath>
           <classpathPrefix />
          </manifest>
          <manifestEntries>
           <url>${pom.url}</url>
           <Implementation-Build>$</Implementation-Build>
           <Implementation-Title>${project.name}</Implementation-Title>
           <Implementation-Vendor>CEJUG</Implementation-Vendor>
           <Implementation-Version>${project.version}</Implementation-Version>
           <Built-By>${user.name}</Built-By>
           <Built-OS>${os.name}</Built-OS>
           <Build-Date>$</Build-Date>
           <SCM>$</SCM>
          </manifestEntries>
         </archive>
        </configuration>
       </plugin>
      </plugins>
     </build>
    </project>
     
  4. Compile and prepare the project for eclipse:
    mvn -Dwtpversion=2.0 compile eclipse:eclipse
Notice the usage of the plugin -Dwtpversion to enable Maven to add Eclipse WTP Support to the project. That simple flag do the trick :). Actually just using that flag will work, but not all plugins of Eclipse will work out of the box without the WebContent folder - it is up to you to decide if it is worthy to modify your project structure or just go straight ahead with the plain Maven folder.
Done, now you can refresh the project in Eclipse and continue to work. Remember that jjust the resources folder is hard coded in Eclipse, the src/main/java continues as Maven expects. Perhaps some day we can have the confluence between the conventions of Maven and Eclipse and then we will finally becomes free of this daily basis hacks.

Convert Exist Eclipse Dynamic Web Project to Maven project


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
     <webResources>
      <resource>
       <directory>$/WebContent</directory>
      </resource>
     </webResources>
     <warSourceDirectory>WebContent</warSourceDirectory>
     <warSourceExcludes>WebContent/WEB-INF/lib/*.jar</warSourceExcludes>
     <archiveClasses>false</archiveClasses>
     <archive>
      <manifest>
       <addClasspath>true</addClasspath>
       <classpathPrefix />
      </manifest>
      <manifestEntries>
       <url>${pom.url}</url>
       <Implementation-Build>$</Implementation-Build>
       <Implementation-Title>${project.name}</Implementation-Title>
       <Implementation-Vendor>CEJUG</Implementation-Vendor>
       <Implementation-Version>${project.version}</Implementation-Version>
       <Built-By>${user.name}</Built-By>
       <Built-OS>${os.name}</Built-OS>
       <Build-Date>$</Build-Date>
       <SCM>$</SCM>
      </manifestEntries>
     </archive>
    </configuration>
   </plugin>

Configure java logger

Basic configurations for Java Logger ( since JDK 1.4)

LoggerManager will load <JRE_HOME>/lib/logging.properties as default logging setttings. In-order to load your own logging settings,
you may need to include the following line during jvm start: 
    
     -Djava.util.logging.config.file=mylogging.properties
where mylogging.properties is my own config base on <JRE_HOME>/lib/logging.properties.


You may also do your own logging.properties during your application startup, the detail please refer to Hildeberto's BLog .