Hello everyone,
I have a problem. I develop a Confluence Macro. I want to conenct to an external database and I can not establish a connection via ActiveObjects. If I use the following way to conenct to an database I get an ClassNotFoundException. (com.mysql.jdbc.Driver)
EntityManager entityManager = EntityManagerBuilder .url("jdbc:mysql://localhost/confluence") .username("root") .password("") .auto() .build();
If I use this way I can nonnect to an database but can not use the ActiveObjects framework.
Driver driver = this.loadDriver("com.mysql.jdbc.Driver"); Properties props = new Properties(); props.setProperty("user", "root"); props.setProperty("password", ""); String url = "jdbc:mysql://localhost/confluecne"; Connection connection = driver.connect(url, props); private Driver loadDriver(final String driverName) throws SQLException { try { final Class clazz = ClassLoaderUtils.loadClass(driverName,CargoSoftCustomerMacro.class); System.out.println("Load new Class.."); return (Driver) clazz.newInstance(); } catch (ClassNotFoundException e) { throw new SQLException("JDBC driver class not found: " + driverName, e); } catch (Exception e) { throw new SQLException("Cannot instantiate JDBC driver class " + driverName + ": " + e.getMessage(), e); } }
I add the com.mysql.jdbc.Driver in my pom.xml and in my classpath from the project. I think the second way works because the right classloader loads the driver and by the first way there are problems beacuase the wrong classloader load the driver and can not find them.
Can anyone help me with this problem?
Thanks for replies!
Greetz
Jan
Community moderators have prevented the ability to post new answers.
Take a look at this page, quite large and complex, but worth reading...
https://developer.atlassian.com/docs/getting-started/working-with-the-pom/managing-dependencies
{quote} In the past, you could add a JAR file to the WEB-INF/lib directory and make it available to all plugins, as well as the product itself. This no longer works, as the plugin system doesn't know about any code in the product beyond what it's been told to use; placing random JARs in WEB-INF/lib or class files in WEB-INF/classes will not make them available in the system bundle. {quote}
Took this from this discussion https://answers.atlassian.com/questions/11991634
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I read the text and I think I understand the function. I have add a dependency in my pom wich includes the mysql driver and scope compile. There is also a classnotfoundexception during call my plugin. The driver is not in my plugin classpath I think. Because when I call the ActiveObjects EntityManager I get the exception. I do not understand the problem. Hope for help! :) Greetz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
h,
I think you need to add a dependency in pom.xml
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.12</version> <scope>install</scope> </dependency>
and you should have the jar file in your target folder.
target\classes\META-INF\lib
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.