Hi all,
Where, I put my external data source when I develop my plugin.
Community moderators have prevented the ability to post new answers.
Hi all,
Thanks for your responses.
I have resolved it like this:
I have changed the jira connexion database in the dbconfig.xml with an external data base and I have used the data base existing in the file context.xml located in this directory my_plugin_home\target\container\tomcat6x\cargo-jira-home\conf.
An explanation how to use atlas-debug environment with an external database can be found here:
Further reading:
A working copy of my JIRA plugin project with PostgreSQL can be found here: https://github.com/RaphaelBossek/dev-atlassian-jira-proman/blob/6b53b288773f1cca03b4ebc81511ff9a01bcd8a0/pom.xml
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I agree with Boris, You can create jndi external datasource as described here using the confluence sdk.
https://developer.atlassian.com/docs/developer-tools/declaring-jndi-datasources-in-amps
Just add in your pom.xml like i did for SDK version 5.8.6.
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-amps-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<instanceId>instanceId1</instanceId>
<products>
<product>
<id>confluence</id>
<instanceId>instanceId1</instanceId>
<version>${confluence.version}</version>
<dataPath>src/main/resources/empty-home</dataPath>
<dataSources>
<dataSource>
<jndi>jdbc/DefaultDS</jndi>
<url>jdbc:postgresql://localhost:5432/confluence</url>
<username>confluence</username>
<password>confluence</password>
<driver>org.postgresql.Driver</driver>
<libArtifacts>
<libArtifact>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</libArtifact>
</libArtifacts>
</dataSource>
<dataSource>
<jndi>jdbc/externalDataSource</jndi>
<url>jdbc:oracle:thin:@host:1525:dbname</url>
<username>SCHEMA</username>
<password>PASSWORD</password>
<driver>oracle.jdbc.OracleDriver</driver>
<libArtifacts>
<libArtifact>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</libArtifact>
</libArtifacts>
</dataSource>
</dataSources>
</product>
</products>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-confluence-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${confluence.version}</productVersion>
<productDataVersion>${confluence.data.version}</productDataVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<confluence.version>5.8.6</confluence.version>
<confluence.data.version>5.8.6</confluence.data.version>
<amps.version>5.0.13</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
</properties>
You might need to clean up your m2 if you are playing with versions. altas-clean and then atlas-run will run the same for you. Hope it will help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can declare datasource in the pom.xml as described here https://developer.atlassian.com/display/DOCS/Declaring+JNDI+Datasources+in+AMPS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then configure context.xml as explained here http://confluence.kepler-rominfo.com/display/DBCF/Data+Source+Configuration
(don't forget the jdbc driver)
And use the sample code here when the plugin needs the connection:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Oracle_8i,_9i_&_10g
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can get code from the following post
https://answers.atlassian.com/questions/6374/how-do-i-access-jndi-from-a-version-2-osgi-plugin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi thanks for reponse,
I have seen this before asked this question (liked it) and I have did this ClassLoader origCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(ComponentManager.class.getClassLoader());
//::TODO:: do lookup here
} finally {
Thread.currentThread().setContextClassLoader(origCL);
}
(I develop a rest plugin) and it work fine when I execute this
InitialContext iContext = new InitialContext();
Context context = (Context) iContext.Lookup("java:com/emp");
DataSource dataSource = (DataSource) context.lookup("jdbc/JiraDS");
System.out.println(dataSource.toString()) return this : org.apache.tomcat.dbcp.BasicDataSource@16e5841.
but when I put in context.lookup("jdbc/MyExternalDataBase") it return an exception
I think that I have not asked question correctly .
So my problem :
Where I put my data source to browse It (file) when I develop my plugin ?
I have tried to put It in this file
Myplugin_home\target\container\tomcat6x\cargo-jira-home\conf\context.xml and It's produced an error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexalready mentioned in his comment to this question, you ned to configure JNDI in server.xm/context.xml as follows
<Resource name="jdbc/MyExternalDataBase" auth="Container" type="javax.sql.DataSource" maxActive="15" maxIdle="100" maxWait="90000" removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true" username="username" password="password" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://;serverName=severname.com;databaseName=test"/>
don't forgot to change username, password and server name, after this changes you need to restart server
then you can access jndi on your plugin as you specified above
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@rambanam prasad
in which directory, I do this changes?
MY_Plugin_Home\Target\...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you need to add above code in jira server not in plugin code!
go to the conf folder in jira installation directory(../JIRA/conf/server.xml)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@rambanam prasad
My need is to connect my plugin when I develop It to do some tests not after installation or It's not possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
then you need to use JDBC to connect external DB, you can get sample code here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is not exactly my need, but I accept this answer because it allowed me to review the use of JDBC.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Alex Perez
Yes, That's what I want.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for yours answers
Just I explain you more:
I would to find my data source in context.xml when Iuse It in production.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well,
you can define the DS in context.xml, but then the plugin must call jndi to locate it.
Note that if you use context.xml tomcat will manage the DS pool and the driver must be deployed to lib/ folder instead of packed with the driver.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have a look on similar question https://answers.atlassian.com/questions/30603/how-do-you-access-other-data-sources-starting-jira-4-3
Hope this helps you,
Patina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi zezeto,
Ive recently developed a plugin that uses a external mysql db :)
The plugin loads the datasource configuration from a properties, located in the JIRA_HOME folder. From the plugin code, the datasource access to the properties with:
try { log.debug("loading driver"); Class.forName("com.mysql.jdbc.Driver"); log.debug("loading properties in JIRA_HOME ..."); Properties connectionProps = new Properties(); File jiraHome = ComponentAccessor.getComponent(JiraHome.class).getHome(); File propertyFile = new File(jiraHome, "CMDB.properties"); FileInputStream stream = new FileInputStream(propertyFile); connectionProps.load(stream); log.debug("getting connection ..."); this.conn = DriverManager.getConnection(connectionProps.getProperty("url"), connectionProps); } catch (Exception e) { log.debug("error connecting to CMDB: " + e.getMessage()); } log.debug("connection initialized.");
Driver is included in pom.xml as dependency, so is embeded in the resulting plugin jarfile.
HTH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.