0

so I'm trying to write a java web service via Eclipse to expose some SQL Server data in XML format

I've some how managed to write a script that returns the SQL Server query results I want

I've also some how managed to set up a basic java web service that exposes XML of some dummy data (stored as a ArrayList) through localhost

All the necessary jars have been added via configure build path

Both work fine separately. But when I remove the dummy data to try and use the data from the query, I keep getting java.lang.NoClassDefFoundError com/microsoft/sqlserver/jdbc/SQLServerDriver errors

My dummy data involves simply hardcoding string data into the ArrayList

I get also get the string values of my query resultset via something like

rs.getObject("FieldName").toString()

I know this works because I can see the data when I print to console.

So I simply replace the hardcoded strings with this but it keeps throwing error

Any advice? enter image description here

user3120554
  • 641
  • 2
  • 11
  • 21
  • You may want to post what the error is. – Ryan Wilson Jul 17 '18 at 14:28
  • Added now. This is a maven web service project. Based on googling, I've also heard that simply adding the SQL server jar file to build path would not work and that you should add it to WEB-INF/lib, although I'm not too sure where that exists in a maven project – user3120554 Jul 17 '18 at 14:51

1 Answers1

0

I managed to resolve it. Mostly this stems from my lack of knowledge between maven and non maven projects.

As I somewhat understand, with a non maven project, you would need to add the SQL server jar to the web-inf/lib folder. Since you're deploying tomcat, and then running the application on it. The tomcat server picks up the jars from that folder

In a maven project, I don't have that folder. Instead, via eclipse, I went into the Servers tab, double clicked on my server, clicked on Open Launch Configuration, and this brings up a similar window to if I were just to add the jar via build path

So in here, I added my SQL server jar, then restarted the server and it worked!

user3120554
  • 641
  • 2
  • 11
  • 21