MySQL Class Not Found Error On The Bitbucket Server Plugin

bitbucket-server
mysql

#1

Hi ,
i am developing a plugin for the Bitbucket Server. i want to connection MySQL server but i have a some problems. How can i fix that problems?

my pom xml file

<dependencies>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-spi</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-page-objects</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.libversion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons.lang3.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>${javax.inject.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- WIRED TEST RUNNER DEPENDENCIES -->
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-osgi-testrunner</artifactId>
            <version>${plugin.testrunner.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>${jsr311.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>${gson.version}</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160810</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.applinks</groupId>
            <artifactId>applinks-api</artifactId>
            <version>5.0.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.templaterenderer</groupId>
            <artifactId>atlassian-template-renderer-api</artifactId>
            <version>1.3.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>7.2.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-refapp-plugin</artifactId>
            <version>3.2.2</version>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.29</version>
            <scope>provided</scope>
        </dependency>
       
    </dependencies>

my java code for the mysql connection

try{
            Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/bitbucket_plugin","root","");
            if(!conn.isClosed())
            {
                String query = "select * from servers,auth where servers.ServerID = auth.ServerID";
                java.sql.Statement statement = (java.sql.Statement) conn.createStatement();
                ResultSet rs = statement.executeQuery(query);
                while(rs.next())
                {
                    String server = rs.getString("ServerName");
                    String token = rs.getString("Token");
                    System.out.println("Server : "+server);
                    System.out.println("Token : "+token);
                }
            }
        }
        catch(SQLException ex)
        {
            System.out.println("SQL Exception : "+ex.getMessage());
        }

logs
[INFO] SQL Exception : No suitable driver found for jdbc:mysql://127.0.0.1/bitbucket_plugin


#2

Hey @youmit94,

are you sure that your scope should be provided in your depency?
Is the library actually there? Or do you still need to install it?

Cheers,
Peter


#3

i am sure , the library is in dependency section.Untitled


#4

And i saw log error messages now

[INFO] 2018-04-18 10:08:17,153 ERROR [spring-startup] c.a.plugin.osgi.factory.OsgiPlugin Detected an error (BundleException) enabling the plugin ‘com.umit.commit.check.commit’ : Unresolved constraint in bundle com.umit.commit.check.commit [130]: Unable to resolve 130.0: missing requirement [130.0] osgi.wiring.package; (osgi.wiring.package=com.mchange.v2.c3p0). This error usually occurs when your plugin imports a package from another bundle with a specific version constraint and either the bundle providing that package doesn’t meet those version constraints, or there is no bundle available that provides the specified package. For more details on how to fix this, see https://developer.atlassian.com/x/mQAN
[INFO] 2018-04-18 10:08:17,153 WARN [spring-startup] c.a.plugin.impl.AbstractPlugin Unable to enable plugin ‘com.umit.commit.check.commit’
[INFO] 2018-04-18 10:08:17,153 WARN [spring-startup] c.a.plugin.impl.AbstractPlugin Because of this exception
[INFO] com.atlassian.plugin.osgi.container.OsgiContainerException: Cannot start plugin: com.umit.commit.check.commit
[INFO] at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:418)
[INFO] at com.atlassian.plugin.impl.AbstractPlugin.enable(AbstractPlugin.java:287)
[INFO] at com.atlassian.plugin.manager.PluginEnabler.actualEnable(PluginEnabler.java:130)
[INFO] at com.atlassian.plugin.manager.PluginEnabler.enable(PluginEnabler.java:107)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.enableDependentPlugins(DefaultPluginManager.java:1248)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.addPlugins(DefaultPluginManager.java:1218)
[INFO] at com.atlassian.stash.internal.plugin.StashPluginManager.addPlugins(StashPluginManager.java:80)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.earlyStartup(DefaultPluginManager.java:597)
[INFO] at com.atlassian.stash.internal.plugin.StashPluginManager.lambda$earlyStartup$0(StashPluginManager.java:55)
[INFO] at com.atlassian.stash.internal.plugin.PluginUpgradeHelper.withUpgrade(PluginUpgradeHelper.java:71)
[INFO] at com.atlassian.stash.internal.plugin.StashPluginManager.earlyStartup(StashPluginManager.java:55)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.init(DefaultPluginManager.java:527)
[INFO] at com.atlassian.stash.internal.plugin.SpringPluginSystemLifecycle.start(SpringPluginSystemLifecycle.java:35)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114)
[INFO] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880)
[INFO] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
[INFO] at javax.servlet.GenericServlet.init(GenericServlet.java:158)
[INFO] at java.lang.Thread.run(Thread.java:748)
[INFO] … 8 frames trimmed
[INFO] Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle com.umit.commit.check.commit [130]: Unable to resolve 130.0: missing requirement [130.0] osgi.wiring.package; (osgi.wiring.package=com.mchange.v2.c3p0)
[INFO] at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
[INFO] … 22 common frames omitted
[INFO] 2018-04-18 10:08:17,727 WARN [ThreadPoolAsyncTaskExecutor::Thread 30] c.a.p.a.a.spring
[INFO] Spring context started for bundle : com.atlassian.plugins.authentication.atlassian-authentication-plugin id(107) v(2.1.0) reference:file:/D:/Bitbucket/commit/target/bitbucket/app/WEB-INF/atlassian-bundled-plugins/atlassian-authentication-plugin-2.1.0.jar
[INFO]
[INFO] If you want to debug the Spring wiring of your code then set a DEBUG level log level as follows. [ This is a dev.mode only message. ]
[INFO] log4j.logger.com.atlassian.plugins.authentication.atlassian-authentication-plugin.spring = DEBUG, console, filelog
[INFO]
[INFO] 2018-04-18 10:08:20,982 ERROR [spring-startup] c.a.plugin.manager.PluginEnabler Unable to enable plugin com.umit.commit.check.commit
[INFO] com.atlassian.plugin.osgi.container.OsgiContainerException: Cannot start plugin: com.umit.commit.check.commit
[INFO] at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:418)
[INFO] at com.atlassian.plugin.impl.AbstractPlugin.enable(AbstractPlugin.java:287)
[INFO] at com.atlassian.plugin.manager.PluginEnabler.actualEnable(PluginEnabler.java:130)
[INFO] at com.atlassian.plugin.manager.PluginEnabler.enable(PluginEnabler.java:107)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.enableDependentPlugins(DefaultPluginManager.java:1248)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.addPlugins(DefaultPluginManager.java:1218)
[INFO] at com.atlassian.stash.internal.plugin.StashPluginManager.addPlugins(StashPluginManager.java:80)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.earlyStartup(DefaultPluginManager.java:597)
[INFO] at com.atlassian.stash.internal.plugin.StashPluginManager.lambda$earlyStartup$0(StashPluginManager.java:55)
[INFO] at com.atlassian.stash.internal.plugin.PluginUpgradeHelper.withUpgrade(PluginUpgradeHelper.java:71)
[INFO] at com.atlassian.stash.internal.plugin.StashPluginManager.earlyStartup(StashPluginManager.java:55)
[INFO] at com.atlassian.plugin.manager.DefaultPluginManager.init(DefaultPluginManager.java:527)
[INFO] at com.atlassian.stash.internal.plugin.SpringPluginSystemLifecycle.start(SpringPluginSystemLifecycle.java:35)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151)
[INFO] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114)
[INFO] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880)
[INFO] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
[INFO] at javax.servlet.GenericServlet.init(GenericServlet.java:158)
[INFO] at java.lang.Thread.run(Thread.java:748)
[INFO] … 8 frames trimmed
[INFO] Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle com.umit.commit.check.commit [130]: Unable to resolve 130.0: missing requirement [130.0] osgi.wiring.package; (osgi.wiring.package=com.mchange.v2.c3p0)
[INFO] at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
[INFO] … 22 common frames omitted
[INFO] 2018-04-18 10:08:20,017 WARN [ThreadPoolAsyncTaskExecutor::Thread 18] c.a.t.plugin-bitbucket.spring
[INFO] Spring context started for bundle : com.atlassian.troubleshooting.plugin-bitbucket id(124) v(1.8.9) reference:file:/D:/Bitbucket/commit/target/bitbucket/app/WEB-INF/atlassian-bundled-plugins/plugin-bitbucket-1.8.9.jar
[INFO]
[INFO] If you want to debug the Spring wiring of your code then set a DEBUG level log level as follows. [ This is a dev.mode only message. ]
[INFO] log4j.logger.com.atlassian.troubleshooting.plugin-bitbucket.spring = DEBUG, console, filelog
[INFO]
[INFO] 2018-04-18 10:08:20,458 WARN [ThreadPoolAsyncTaskExecutor::Thread 34] c.a.p.a.spring
[INFO] Spring context started for bundle : com.atlassian.plugins.atlassian-remote-event-common-plugin id(104) v(3.0.0) reference:file:/D:/Bitbucket/commit/target/bitbucket/app/WEB-INF/atlassian-bundled-plugins/atlassian-remote-event-common-plugin-3.0.0.jar
[INFO]


#5

i think , that errors is not about mysql library but i couldn’t fix the my problem. My plugin is not working while that mysql dependency in my pom.xml. Please help me for the that problem.


#6

@youmit94,

We do not allow plugin developers to access the JDBC libraries at runtime, and we do not support add-ons talking directly to the database. The classpath in your editor may show it, but your plugin will not be able to access it at runtime. (In other words, it’s not <scope>provided</scope>.)

What are you trying to do with the database? If you want to store some data in a database table, the only supported approach is to use ActiveObjects.

Best regards,
Bryan Turner
Atlassian Bitbucket

Edit: Also, note that bitbucket-page-objects, jira-api and maven-refapp-plugin are also not provided at runtime. bitbucket-page-objects is only for <scope>test</scope> as part of building browser-based integration tests. jira-api is only provided for Jira plugins; it’s not available in any other product. maven-refapp-plugin is only part of building a plugin for the refapp, so you shouldn’t need it at all.