Trying to execute SQL in a confluence plugin to a jiraDS datasource define in the confluence configuration file. Plugin has dependencies for jira-api and jira-core defined with 'provided' as value for <scope>provided</scope>. The subsequent atlas-compile and atlas-package build and packaging has no errors. The resulting plugin jar file was too large at 76Mbytes and the limit on the server was defaulted to 67Mbytes. I proceeded to copy just the class files that i used my code and reduced the file size to about 1Mbyte, which uploaded as an add on plugin with no errors. When going to a page that has the plugin it then throws this error:
Caused by: java.util.MissingResourceException: Can't find bundle for base name cache, locale en_US
Code used in plugin to attempt to getConnection():
try {
DefaultOfBizConnectionFactory factory = DefaultOfBizConnectionFactory.getInstance();
Connection connection = factory.getConnection();
// do something with connection
} catch (SQLException sqle) {
String message = sqle.getMessage();
}
Is there another way to reduce the plugin jar file size without piece mealing the classes folder with required classes? Is there a better way to get a connection object for executing SQL in a plugin without doing straight jdbc? I'd like to reuse the defined 'jiraDS' datasource in Confluence's configuration file.
No need to include any jira-api or jira-core pom.xml dependencies in your confluence plugin and the plugin jar file size was less then 500Kbytes. The nice thing here is that it uses your confluence server's configured datasource for JIRA instead of you having to code it in the plugin config or JAVA code.
After trying what seems like 10 different ways to access JIRA data from a Confluence Plugin, i finally found that this worked:
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.sql.DataSource;
private String sqlJNDITest() {
String res = "NONE";
DataSource dataSource;
try {
InitialContext initalContext = new InitialContext();
Context context = (Context) initalContext.lookup("java:comp/env");
dataSource = (DataSource) context.lookup("jdbc/<your_datasource_name>");
Connection connection = dataSource.getConnection();
res = connection.getCatalog();
String query = "select * from jiraissue where id=<your_jiraissue_id>";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String summary = rs.getString("summary");
res = res + summary;
}
} catch (NamingException ex) {
String message = ex.getMessage();
} catch (SQLException sqle) {
String message = sqle.getMessage();
}
return res;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.