Thursday, July 18, 2013

Download a library from maven manually

There are times when you want to manually download a maven library using command line then use the local version in your pom file.

First you can download a library from maven using the following command. For example the following mvn command downloads a a library from maven and installs it in your local maven repo.


mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -Dartifact=org.springframework:spring-instrument:3.1.1.RELEASE -DrepoUrl=repository.sonatype.org/content/repositories/central

or something like so

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get  -Dartifact=com.restfuse:com.eclipsesource.restfuse:1.2.0 -DrepoUrl=repository.sonatype.org/content/repositories/central


Then in your maven config you can add the following snippit in your pom. 

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-instrument</artifactId>
    <version>3.1.1</version>
   <!--Optionally if you downloaded it to some non-standard folder    
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/spring-instrument-3.1.1.jar</systemPath>
   -->
</dependency>









Wednesday, July 3, 2013

Wrapping an existing ant target so you can pass in a javaagent and other jvm args

If you have an ant task that requires a javaagent such as spring's instrument.jar,
you might get this stack error message.

Caused by: java.lang.IllegalStateException: ClassLoader [org.apache.tools.ant.loader.AntClassLoader5] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar



Solution is to wrap the offending ant target with the javaagent:org.springframework.instrument.jar




So:
if your build.xml   file has the following target,  

  <target name="create-sql">
       .... code that requires javaagent
    </target>

then you would add a new wrapper target, like so:

 <target name="build-create-sql" >
        <!--wrapping spring insturment jar-->
            <java  classname="org.apache.tools.ant.launch.Launcher"
                    fork="true"
                    failonerror="true"
                    dir="."
                    timeout="4000000"
                    taskname="startAnt">
                    <classpath>
                        <pathelement location="${ant.home}/lib/ant-launcher.jar"/>
                    </classpath>
                    <jvmarg value="-javaagent:${spring.instrument.path}"/>
                     <jvmarg value="-XX:MaxPermSize=512M" />
                    <jvmarg value="-Xmx1024M" />
                    <arg value="-buildfile"/>
                    <arg file="build.xml"/>
                    <arg value="create-sql"/>
              </java>

    </target>



Now you can pass in a spring instrument jar as a jvmarg and javaagent in your new ant target and the existing target does not have to be modified.





Monday, April 1, 2013

running maven jetty causes Duplicate fragment name error


Sometimes you get the following error from jetty when running demosite.
[artifact:mvn] java.lang.IllegalStateException: Duplicate fragment name: spring_web for jar:file
[artifact:mvn] at org.eclipse.jetty.webapp.MetaData.addFragment(MetaData.java:253)


Solution is to add to your pom.xml:                   
 <webAppConfig> 
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
 </webAppConfig

like so inside your jetty plugin configuration.
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <configuration>
      ...
      <webAppConfig>
        ...
        <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
        ...
      </webAppConfig>
      ...
    </configuration>
  </plugin>

Thursday, January 10, 2013

Git Creating a new Repository from an existing repository


Create a new Git Repository from exising repository.


cp -r ExistingRepo NewRepo
cd newRepo
git remote rm origin
git remote add origin https://github.com/BroadleafCommerce/NewRepo.git
git remote add upstream-existingRepo https://github.com/BroadleafCommerce/ExistingRepo.git
#make sure that you cant push back into upstream.
git remote set-url --push upstream-existingRepo no-pushing


Friday, July 20, 2012

Create a keystore for SSL using maven

Normally you would buy a trusted certificate however, the poor man's way is to create one your self.

Put this in a pom.xml and run it with mvn install.


<project>
<modelVersion>1.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build><plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<phase>generate-resources</phase>
<id>genkey</id>
<goals>
<goal>genkey</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>example.keystore</keystore>
<dname>cn=localhost</dname>
<keypass>broadleaf</keypass>
<storepass>broadleaf</storepass>
<alias>broadleaf</alias>
<keyalg>RSA</keyalg>
</configuration>
</plugin>
</plugins>
</build>
</project>


SSL on tomcat

To turn on SSL port in tomcat is a simple process. You will need to modify the configuration file context.xml to allow the port to be open.


  1. Create the keyStore file to be used for ssl.  Click here to  create one using maven. 
  2.  In your tomcathomedir/conf/server.xml, add the following:


    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"                keystoreFile="/tmp/example.keystore"
               keystorePass="somePassword"               clientAuth="false" sslProtocol="TLS" />

That's it.....
Now hit the url  in your browser , https://localhost:8443 and it should ask your for security exception.   



Thursday, June 21, 2012

Invoking specific locale in gwt application



To invoke a specific locale from a gwt application using the URL,

add the get parameter locale=<string> where
string is the locale defined in your module file.  

for example:
Make sure your gwt module xml file contains the language you are trying to set.


<?xml version="1.0" encoding="UTF-8"?>
<module>
    <inherits name="com.google.gwt.user.User" />
    <inherits name="org.broadleafcommerce.openadmin.userModule" />
    <inherits name="com.google.gwt.core.CompilerParameters"/>
    <inherits name="com.google.gwt.i18n.I18N"/>
    <extend-property name="locale" values="en_US"/>
    <extend-property name="locale" values="es"/>
    <extend-property name="locale" values="es_MX"/>
    <extend-property name="locale" values="fr"/>
    <set-property-fallback name="locale" value="en_US"/>
<entry-point class="org.broadleafcommerce.openadmin.client.BLCLaunch" />
</module>