Thursday, February 10, 2011

Soapui and external jars

1- The Gui version
   1.1 - Adding external jar in a special folder solve this..
  
According to the SoapUi documentation in their SOAPUI_LOCATION\bin\ext\readme.txt , you can access to any external jars if you add it in this folder :

soapUI ext folder; place external jars that should be added to soapUI classpath here, 
for example JDBC drivers, custom libraries, etc..
Good Luck!

Remember the good luck part, you will understand it later.

Now close et opend again Soapui.

If it is working , you will read this in the logs :
INFO  [SoapUI] Added [jar_file] to classpath

   2.2 - ..but not always, so here is the trick

That is half true. If you are using soapui >3.5.1, and are using a jdbc driver for example it will not work any more.

You may face this NoClassDefFoundError
An error occured [org/mum/yourSuperDriver], see error log for details
java.lang.NoClassDefFoundError: org/mum/yourSuperDriver

You just need to add :
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( driverClassName )


But, this method DOESN'T exist in the 3.5.1 version.  
And how do i avoid any person to complain about SoapUi tests not working anymore because he is using an old/new version ?

I have already explain in the MySuperWiki to use the XY version of soapui but nobody read it :(.


Add a verification of the soapui used in a groovy script.
if it fails, throw any exception explaning the culprit to use an early version of soapui.

this line of code return log.info com.eviware.soapui.SoapUI.SOAPUI_VERSION
for soapui 3.5.1 will print "3.5.1".
 

 2-The maven plugin

   2.1 The dirty solution


Place any external jars in your base_dir\ext. or use themaven-dependency-plugin to do it automatically

 <plugin>
   <artifactId>maven-dependency-plugin</artifactId>
     <version>2.1</version> 
     <executions>
      <execution>
        <id>copy-postgresql-artifact</id>
        <phase>generate-resources</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/ext</outputDirectory>
          <destFileName>postgresqlXXX.jar</destFileName>
          <artifactItems>
            <artifactItem>
              <groupId>postgresql</groupId>
              <artifactId>postgresql</artifactId>
              <version>XXX</version>
            </artifactItem>
          </artifactItems>
        </configuration>
      </execution>
    </executions>
  </plugin>


> What dont you try to tell to Soapui that the ext folder will be an other one of your choice ?
> Because this path (at least for the 3.5.1 version) is hardcoded in the soapui source.

And if you do that, you will need to add use the maven-clean-plugin in order to
not only delete the target directory during the clean phase but this jar too.
(see fileset tag of this plugin).

 2 .2 The elegant one

I feel a bit stupid of not having thought about it at the beginning.
Because i was trying to answer to the question : How can i add a jar in the ext folder ?

Sometimes the most difficult part is not to find the correct answer to a question  but to ask the right question.


Add it like a depedency to your soapui plugin. It will bed added to the classpath.
The soapui log will warn you about not having foundin anything in the ext folder.

<plugin>
  <groupId>eviware</groupId>
  <artifactId>maven-soapui-plugin</artifactId>
  <version>3.5.1</version>
  <dependencies>
    <dependency>
      <groupId>postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>${postgresql.version}</version>
    </dependency>
  </dependencies>



I'm open to any suggestion, especially about my english as it is not my mother tongue.
Just add a comment below and i will correct it.

1 comment:

  1. "Remember the good luck part, you will understand it later." :D

    ReplyDelete