3
In my java web application ,I needed to add a connection to a sql server database, so I put it as a dependency on Maven as described below:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>compile</scope>
</dependency>
The dependency has been downloaded and is inside the folder m2.
Running the application locally on my machine, everything works with the import code below:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
However, after generating the WAR of the project with the mvn clean package -DskipTests -Pdev
and posted within a development server, I have the following error:
Root cause of Servletexception. java.lang.Noclassdeffounderror: with/microsoft/sqlserver/jdbc/Sqlserverdriver
I believe, either I’m importing wrong in the code or I forgot to set something up for Maven.
I also checked that after running the Maven command the dependency is placed inside WEB-INF\lib
as the other dependencies, but my application does not find, someone can help me?
On this development server, isn’t there another JAR added with the same name in an older version? Using Tomcat?
– Dherik
To run local I use Tomcat, but on the development server I published is Weblogic
– Felipe
Check if you do not have in this Weblogic a driver already added with the same name. It may be that two Jars with the same name exist in different versions, then in the classpath the first of them is considered and, perhaps, is occurring to find the old one before. This package has changed from one version to another, so I think it’s a possibility.
– Dherik
I got it, I’ll check. Another question, these JARS after build by Maven go to the WEB-INF/lib folder and application will "read" this folder or the server JARS folder?
– Felipe
Of the two. Depending on the application server, you even have the option to choose between trying to find the dependencies first on the server itself and then inside the application (and vice versa), to avoid this type of problem that I mentioned earlier. I believe that Weblogic has this control, including (if you have), you can try to change to your deploy this, but I can’t tell you how pq do not know Weblogic
– Dherik
But if it were inside the application the import path would be the same? " com.microsoft....."
– Felipe
Let’s go continue this discussion in chat.
– Dherik