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