Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do you persist database connections in server.xml when developing using the SDK?

David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 9, 2012

It's easy to access an external database from within Confluence...

You specify something like this in <install-dir>/conf/server.xml:

&lt;Resource name="jdbc/myDataSource"
          auth="Container" 
          type="javax.sql.DataSource"
          username="myusername"
          password="mypassword"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/mydatabase?useUnicode=true&amp;amp;characterEncoding=utf8"
          maxActive="15"
          maxIdle="7"
          defaultTransactionIsolation="READ_COMMITTED"
          validationQuery="Select 1" /&gt;

But during development, how do you get this resource to persist after issuing the atlas-run command?

Any edits to target/container/tomcat6x/cargo-confluence-home/conf/server.xml are overwritten on atlas-run

I'm thinking along the lines of a specially created tomcat zip file (including an updated server.xml file) similar to how the cargo-maven2-plugin works:

&lt;plugins&gt;
  &lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.cargo&lt;/groupId&gt;
    &lt;artifactId&gt;cargo-maven2-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
      &lt;container&gt;
        &lt;containerId&gt;tomcat5x&lt;/containerId&gt;
        &lt;zipUrlInstaller&gt;
          &lt;url&gt;http://www.apache.org/dist/jakarta/tomcat-5/v5.0.30/bin/jakarta-tomcat-5.0.30.zip&lt;/url&gt;
          &lt;downloadDir&gt;${project.build.directory}/downloads&lt;/downloadDir&gt;
          &lt;extractDir&gt;${project.build.directory}/extracts&lt;/extractDir&gt;
        &lt;/zipUrlInstaller&gt;
      &lt;/container&gt;
    &lt;/configuration&gt;
  &lt;/plugin&gt;
&lt;/plugins&gt;

All suggestions are welcome. Extra points for working code :)

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 25, 2012

Another way of tackling this is to create your own tomcat zip as described by @Radu here in step 18:
https://answers.atlassian.com/questions/11337/using-mysql-instead-of-hsql-db-with-atlassian-pdk?page=1#12035

Quoted and adapted below:

create apache-tomcat-6.0.20.zip with edited server.xml file. And then using "maven install" update your maven repository to use this file instead of standard tomcat zip that you downloaded from atlassian maven repository.

atlas-mvn install:install-file -DgroupId=org.apache.tomcat -DartifactId=apache-tomcat -Dversion=6.0.20 -Dfile=apache-tomcat-6.0.20.zip -Dpackaging=zip -DgeneratePom=false

0 votes
Roger Weinheimer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 18, 2013

Why wouldn't you set up a db config in confluence-home and use atlas-create-home-zip (https://developer.atlassian.com/display/DOCS/atlas-create-home-zip)? I haven't actually tried this, but it seems like it would work as follows.

# atlas-run

# edit the db settings in plugin confluence-home

# ctrl-c

# atlas-create-home-zip and associated settings

# atlas-run

Roger Weinheimer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2013

Just tried it and it seems like you need a pre-existing Confluence DB to get it to work. I get an error in the log.

Table 'apreference.bandana' doesn't exist

0 votes
Deleted user June 29, 2012

Hi David,

I have the same problem where the changes in cargo-jira-home>conf>server.xml are not persisted. I tried your solution but didn't have any luck.

I installed the SDK and ended up with the following structure:

target>container>tomcat6x>apache-tomcat-6.0.20>conf

target>container>tomcat6x>cargo-jira-home>conf

This is the error I get: [commons.jira.kconfig.PluginConfiguration] Database JNDI >>StagingDB<< is not defined
I changed the server.xml located under apache-tomcat-6.0.20 but didn't fix the problem. I zipped the apache-tomcat-6.0.20 directory and installed it with the server.xml change but no change.
Changed the server.xml under cargo-jira-home but it gets overwritten.
Any idea what else I can try?
I have the following settings:
&lt;Context path="/jira" docBase="/Path/amps-standalone/target/jira/jira.war" debug="2"&gt;

          &lt;Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/&gt;

      &lt;Resource name='jdbc/StagingDB'
              auth='Container'
              type='javax.sql.DataSource'
              username='x'
              password='x'
              driverClassName='oracle.jdbc.OracleDriver'
              url='jdbc:oracle:thin:@x:9999:x'
           connectionProperties="SetBigStringTryClob=true"
          /&gt;
&lt;/Context&gt;


MB August 14, 2015

We have the same problem. Have you found solution? Thx. Martin

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2012

I'm usually solving this via an ant-maven-plugin. Of course, feel free to adapt it, add conditions, etc

That being said, I'm leaving the code to speak for itself :) - it is an excerpt from some project of mine.

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>prepare-directories</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
............................

<echo message="MYBATIS.GEN: [2.2] Patching generator file ..." />

<!-- load in var additional-xml the dynamically generated fragment -->
<loadfile property="additional-xml"
srcfile="${project.build.directory}/generated-sources/mybator.fragment" />

<!-- This looks for AUTOGENTABLES string (including comments tags) and replaces it with what was generated -->
<replace file="${project.build.directory}/generated-sources/ibatis-generator-config.xml"
token="&lt;!--AUTOGENTABLES--&gt;"
value="${additional-xml}"/>

</tasks>
</configuration>
</execution>

..........................

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2012

And for reference, a technique that I use when you do not have, as shown above, a token to rely on.

If you need to add some config between:

===

<Context>

<!-- ..... here, I mean -->

</Context>

===

you just have to define you fragment like this:

===

<Resource ..../></Context>

===

Then:

use the token as : token="&lt;/Context&gt;"

The result will be:

===

<Context>

<!-- ..... here, I mean -->

<Resource ..../></Context>

===

HTH

Michael Podvinec June 17, 2012

I'm fighting with the same issue as David.
Radu, your solution seems to work somewhat for me, but it gets executed at the wrong point in time during the atlas-debug or atlas-run execution.

The changes are made in the server.xml file, but around the moment the log outputs:
"[INFO] [talledLocalContainer] Tomcat 6.x starting...", the server.xml is overwritten with a fresh copy.

I realize I expose my broad-sweeping ignorance of all things maven here... but how can I schedule an antrun plugin to execute once the tomcat files have been written, but before tomcat is started up?

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2012

1) First, I have to admit that my builds are usually customized (i.e. I do not use atlas-....). It's just maven.

2) Next: find your executing goals like this:

atlas-mvn help:describe -Dcmd=(command_from_atlas_run_or_whatever)

(Atl scrips, AFAIK, are using some atl plugins to do the dispatching to bamboo, jira, etc)

You will see the actual execution. Choose a phase and a goal carefully and do your stuff

HTH

0 votes
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 9, 2012

Just to confirm, this is for use with external datasources, not switching Confluence from the embedded DB :)

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events