|
Our team need a plugin that can access our local SQL server. I used traditional jdbc call
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();; String conStr = "jdbc:sqlserver://myserver;databaseName=Eps" con = DriverManager.getConnection(conStr, uId, pswd); stmt = con.prepareStatement(sqlStm); ResultSet rs = stmt.executeQuery(sqlStm); An ClassNotFoundException returned to load the class. The class is in a sqljdbc4.jar. Unlike regular java console program that I can see the CLASSPATH, I do not know how to get this jar loaded. To bypass the problem, I tied to put the jar file in [JENKINS_ROOT]/jre/lib, hope it will load, with no luck. Questions: 1) Is there a way to set the CLASSPATH where plugin can load it? 2) If CLASSPATH cannot be set, where should I put a jar file so that it can be found by the loader? 3) Is the connection string correct? |
|
Why not set it as a dependency of your plugin? That way the Jenkins
class loader will be able to find it correctly. You may need to install the jar to your local maven repo for this to work since I don't think that the MSSQL JDBC driver is in any common repo. slide On Tue, Jul 31, 2012 at 4:10 PM, chewan mak <[hidden email]> wrote: > Our team need a plugin that can access our local SQL server. I used > traditional jdbc call > > Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();; > String conStr = "jdbc:sqlserver://myserver;databaseName=Eps" > con = DriverManager.getConnection(conStr, uId, pswd); > stmt = con.prepareStatement(sqlStm); > ResultSet rs = stmt.executeQuery(sqlStm); > > An ClassNotFoundException returned to load the class. The class is in a > sqljdbc4.jar. Unlike regular java console program that I can see the > CLASSPATH, I do not know how to get this jar loaded. To bypass the problem, > I tied to put the jar file in [JENKINS_ROOT]/jre/lib, hope it will load, > with no luck. > > Questions: > 1) Is there a way to set the CLASSPATH where plugin can load it? > 2) If CLASSPATH cannot be set, where should I put a jar file so that it can > be found by the loader? > 3) Is the connection string correct? -- Website: http://earl-of-code.com |
|
In reply to this post by chewan mak
It turns out that I can put the jar file in WEB-INF\lib of my plugin.
|
|
On 08/01/2012 01:39 PM, chewan mak wrote:
> It turns out that I can put the jar file in WEB-INF\lib of my plugin. This should happen automatically if it is a <dependency> of your plugin project; could be <scope>runtime</scope> in this case. (If you prefer flexibility over convenience, you can also change the Class.forName call to pass in a ClassLoader - such as a URLClassLoader configured to load the driver JAR from a location of your choice. But in this case it looks like your plugin is hard-coding details of the JDBC connection anyway, so you might as well bundle the driver.) |
| Powered by Nabble | Edit this page |
