You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by ghostwolf59 <ma...@commerce.wa.gov.au> on 2014/10/01 04:04:26 UTC

maven dependency issue (sqljdbc4.jar not picked up during junit test)

Hi,
I am scratching my head on this one.

Have this component that rely on MSSQL Server 2008.

The one developed this rely on sqljdbc4.jar (v3.0) being added to the local
java installation (JAVA_HOME/jre/lib/etc/

I found this a bit silly that each developer working on this component need
to tweak their local java runtime env like this and thought that simply
adding this jar to the pom dependency should resolve this easily.
So I added the sqljdbc4.jar (v3.0) to our internal repo and updated the
project pom.xml dependency to include this...
        <dependency>
            <groupId>org.Microsoft.jdbc</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>3.0</version>
            <scope>test</scope>
        </dependency>

However, when doing so the junit test fail at a very early stage... (85
errors)

The following exception is thrown when using sqljdbc4.jar...
java.lang.IllegalStateException: Failed to load ApplicationContext
	at
org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
	at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
	at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
	at
org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'underInvestigationDAO': Injection of autowired
dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: private org.hibernate.SessionFactory
au.xxx.xx.xxxxxx.service.licence.search.UnderInvestigationDAO.sessionFactory; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
*Error creating bean with name 'licenceServiceUserSessionFactory' defined in
class path resource [WEB-INF/test-web-application-context.xml]: *
Invocation of init method failed; nested exception is
java.lang.AssertionError


Failing to use sqljdbc4.jar made me try to use sqljdbc.jar instead, it runs
longer but still fail (7 failures)
	<dependency>
		<groupId>org.Microsoft.jdbc</groupId>
		<artifactId>sqljdbc</artifactId>
        <version>3.0</version>
        <scope>test</scope>
	</dependency>
 
The following exception is thrown when using sqljdbc.jar...
java.lang.UnsupportedOperationException: Java Runtime Environment (JRE)
version 1.6 is not supported by this driver. Use the sqljdbc4.jar class
library, which provides support for JDBC 4.0.
	at
com.microsoft.sqlserver.jdbc.SQLServerConnection.<init>(SQLServerConnection.java:238)
	at
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
	at java.sql.DriverManager.getConnection(DriverManager.java:582)
	at java.sql.DriverManager.getConnection(DriverManager.java:154)
	at
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
	at
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
	at
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
	at
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
	at
org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
	at
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
	at
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
	at
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1616)
	at org.hibernate.loader.Loader.doQuery(Loader.java:717)
	at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)



I've done this in the past on other components using v4.0 without any issues
so I thought this one would be dead simple, but I don;t seem to be able to
do this successfully without 
adding sqljdbc4.jar to the JAVA_HOME/jre/lib/etc/ folder. - Once there (and
without any pom dependency) it runs without any issues.

Don't understand why this is a problem - other components I've worked on
that connects to MS SQL Server 12 using sqljdbc4.jar (v4.0) works perfectly.
Using sqljdbc4.jar as part of my pom dependency prevents the
WEB-INF/test-web-application-context.xml to be resolved
But by adding the sqljdbc4.jar to the JAVA_HOME/jre/lib/etc/ folder works! -
Why???? 
Is this something linked to the v3.0 or...?

Bottom line is that I don't want developers to be forced to tweak their
local java environment like this where I would expect maven to sort the pom
dependency, but it doesn't!

The component is built using ...
* jdk1.6.0_33
* apache-maven-3.0.4
* Junit 4.11
* spring 3.0.4.RELEASE
* hibernate 3.5.6-Final





-----
good @ being sucked @
--
View this message in context: http://maven.40175.n5.nabble.com/maven-dependency-issue-sqljdbc4-jar-not-picked-up-during-junit-test-tp5807497.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org