How do I stop ServiceStack 3.9.71 NuGet package installing ServiceStack.Text 4.0.24? - licensing

I have a project that uses ServiceStack; we're running the old 3.9.x codebase rather than upgrading to 4.x, since ServiceStack 4 requires a commercial license.
My own API client has a dependency defined in the .nuspec file as follows:
<dependencies>
<dependency id="DotNetOpenAuth.OAuth2.Client" version="[4.3,5)" />
<dependency id="log4net" version="[2.0,2.1)" />
<dependency id="ServiceStack" version="[3.9.71,4)" />
</dependencies>
Problem is - the ServiceStack package depends on various other bits of the ServiceStack framework, and installing ServiceStack 3.9.71 is installing ServiceStack.Text v4.0.24 into my project. It does pop up the dialog requiring license acceptance, which is what alerted me that something weird was going on - but short of manually defining my own dependencies for the other required ServiceStack components, how can I make sure I'm not going to end up with unlicensed bits of ServiceStack 4.x in my project?

Make the ServiceStack.Text dependency explicit in your .nuspec and put it before the ServiceStack dependency.
<dependencies>
<dependency id="DotNetOpenAuth.OAuth2.Client" version="[4.3,5)" />
<dependency id="log4net" version="[2.0,2.1)" />
<dependency id="ServiceStack.Text" version="[3.9.71,4)" />
<dependency id="ServiceStack" version="[3.9.71,4)" />
</dependencies>
This will force NuGet to resolve ServiceStack.Text using the constraint.
The problem with just installing ServiceStack using the version range [3.9.71,4) is that NuGet resolves the ServiceStack.Common dependency to the lowest compatible version of ServiceStack.Common which it determines is version 3.9.11. ServiceStack.Common 3.9.11 does not specify a dependency range for ServiceStack.Text so NuGet installs a 4.0 version. Later versions of ServiceStack.Common do have a range for the ServiceStack.Text package but the older versions do not. So without making the dependency explicit or having the ServiceStack.Text NuGet package changed so it puts in a range, there is not much you can do when installing your NuGet package.
The only other thing you can do is put a constraint in your packages.config file to prevent the newer version of ServiceStack being installed.
<packages>
<package id="ServiceStack.Text" version="3.9.71" allowedVersions="[3.9.71,4)" />
</packages>

I made my own "wrapper" package for this containing no extra files but only dependencies - like this:
<dependencies>
<dependency id="ServiceStack.Text" version="[3.9.71]" />
<dependency id="ServiceStack.Common" version="[3.9.71]" />
<dependency id="ServiceStack.Redis" version="[3.9.71]" />
<dependency id="ServiceStack.OrmLite.SqlServer" version="[3.9.71]" />
<dependency id="ServiceStack" version="[3.9.71]" />
</dependencies>

Related

Ubuntu upgrade (14.04.3) and solr upgrade (5.3) breaks solr3/jetty setup

While upgrading our production server to ubuntu 14 the solr/jetty broke.
To fix i tried:
- upgraded java version to 8.
- upgraded solr to 5.3
My earlier config used .war files. realized that now its stopped supporting .war files, so now cannot use my earlier config.
This was the steps i used earlier:
copy the solr.war file from the downloaded and untarred solr to the webapps folder, and make jetty owner:
sudo cp ~/x/apache-solr-3.6.1/dist/apache-solr-3.6.1.war /usr/share/jetty/webapps/solr.war
sudo chown jetty:jetty /usr/share/jetty/webapps/solr.war
create a context file in JETTY_HOME/contexts (sudo vim /usr/share/jetty/contexts/solr.xml)
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<!-- Set the solr.solr.home system property -->
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Call name="setProperty" class="java.lang.System">
<Arg type="String">solr.solr.home</Arg>
<Arg type="String">/usr/share/solr</Arg>
</Call>
</Configure>
tell solr how many cores we have and what those are in SOLR_HOME (sudo vim /usr/share/solr/solr.xml):
<solr persistent="true" sharedLib="lib">
<cores adminPath="/admin/cores">
<core name="demo" instanceDir="demo" />
<core name="dev" instanceDir="dev" />
<core name="qa" instanceDir="qa" />
<core name="www" instanceDir="www" />
</cores>
</solr>
etc.
Don't want to use the solr instance that comes with rsolr (4), if i can help it. But can't find corresponding info for solr 5.3
Running rails 3.2.21. and solr_sunspot gem 2.2.0
Thanks in advance!

cxf-codegen-plugin illegal configuration-file syntax

I am trying to update some web services code developed for Java 6 to Java 8. The modules use the maven cxf-codegen-plugin. The Java 6 version used cxf version 2.2.2. I was able to get it working with Java 7 by updating cxf to 2.7.9 but haven't be able to build under Java 8. I tried updating cxf to 3.0.3 but still get this error:
XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sum.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.xml.xpath.XPathFactory: jar:file:/c:/Documents%20and%20Settings/Kevin/.m2/repository/saxon/saxon-xpath/8.9.0.3/saxon-xpath-8.9.0.3.jar!META-INF/services/javax.xml.xpath.XPathFactory:2: Illegal configuration-file syntax
I am using jdk 1.8.0_31, maven 3.0.3 and cxf 3.0.3.
The problem comes from an incompatible version of saxon-he. It can easily be solved by adding a fixed version to the classpath oth the maven plugin (as dependency):
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf-version}</version>
<dependencies>
<dependency>
<groupId>org.daisy.libs</groupId>
<artifactId>saxon-he</artifactId>
<version>9.5.1.5</version>
</dependency>
</dependencies>
<executions>

Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0

I am trying to add MS SQL driver dependency in my POM.xml file and the following is the dependency.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
but I get this exception
Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0
I really don't understand the issue.
UPDATE
Microsoft now provide this artifact in maven central. See #nirmal's answer for further details: https://stackoverflow.com/a/41149866/1570834
ORIGINAL ANSWER
The issue is that Maven can't find this artifact in any of the configured maven repositories.
Unfortunately Microsoft doesn't make this artifact available via any maven repository. You need to download the jar from the Microsoft website, and then manually install it into your local maven repository.
You can do this with the following maven command:
mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar
Then next time you run maven on your POM it will find the artifact.
Microsoft recently open sourced their jdbc driver.
You can now find the driver on maven central:
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
or for java 7:
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre7</version>
</dependency>
I had the similar problem and solved it by doing following.
Download sqljdbc4.jar from the Microsoft website to your local machine.
Right click on Project-->Import-->Maven-->Install or deploy an artifact to a Maven repository as shown below.
* Next-->Fill the following details
Artifact file:
path of the jar you downloaded (Ex: E:\lib\sqljdbc4.jar in my case)
Group Id: com.microsoft.sqlserver
Artifact Id: sqljdbc4
Version: 4.0
Then Refresh/clean the project.
Thank you!
You can also create a project repository. It's useful if more developers are working on the same project, and the library must be included in the project.
First, create a repository structure in your project's lib directory, and then copy the library into it. The library must have following name-format: <artifactId>-<version>.jar
<your_project_dir>/lib/com/microsoft/sqlserver/<artifactId>/<version>/
Create pom file next to the library file, and put following information into it:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.2.0</modelVersion>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.2</version>
</project>
At this point, you should have this directory structure:
<your_project_dir>/lib/com/microsoft/sqlserver/sqljdbc4/4.2/sqljdbc4-4.2.jar
<your_project_dir>/lib/com/microsoft/sqlserver/sqljdbc4/4.2/sqljdbc4-4.2.pom
Go to your project's pom file and add new repository:
<repositories>
<repository>
<id>Project repository</id>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
Finally, add a dependency on the library:
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.2</version>
</dependency>
</dependencies>
Update 2017-03-04
It seems like the library can be obtained from publicly available repository. #see nirmal's and Jacek Grzelaczyk's answers for more details.
Update 2020-11-04
Currently Maven has a convenient target install which allow you to deploy an existing package into a project / file repository without the need of creating POM files manually. It will generate those files for you.
mvn install:install-file \
-Dfile=sqljdbc4.jar \
-DgroupId=com.microsoft.sqlserver \
-DartifactId=sqljdbc4 \
-Dversion=4.2 \
-Dpackaging=jar \
-DlocalRepositoryPath=${your_project_dir}/lib
The above answer only adds the sqljdbc4.jar to the local repository. As a result, when creating the final project jar for distribution, sqljdbc4 will again be missing as was indicated in the comment by #Tony regarding runtime error.
Microsoft (and Oracle and other third party providers) restrict the distribution of their software as per the ENU/EULA. Therefore those software modules do not get added in Maven produced jars for distribution. There are hacks to get around it (such as providing the location of the 3rd party jar file at runtime), but as a developer you must be careful about violating the licensing.
A better approach for jdbc connectors/drivers is to use jTDS, which is compatible to most DBMS's, more reliable, faster (as per benchmarks), and distributed under GNU license. It will make your life much easier to use this than trying to pound the square peg into the round hole following any of the other techniques above.
just add
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>runtime</scope>
</dependency>
For self-containing Maven project I usually installing all external jar dependencies into project's repository. For SQL Server JDBC driver you can do:
download JDBC driver from https://www.microsoft.com/en-us/download/confirmation.aspx?id=11774
create folder local-repo in your Maven project
temporary copy sqljdbc42.jar into local-repo folder
in local-repo folder run mvn deploy:deploy-file -Dfile=sqljdbc42.jar -DartifactId=sqljdbc42 -DgroupId=com.microsoft.sqlserver -DgeneratePom=true -Dpackaging=jar -Dversion=6.0.7507.100 -Durl=file://. to deploy JAR into local repository (stored together with your code in SCM)
sqljdbc42.jar and downloaded files can be deleted
modify your's pom.xml and add reference to project's local repository:
xml
<repositories>
<repository>
<id>parent-local-repository</id>
<name>Parent Local repository</name>
<layout>default</layout>
<url>file://${basedir}/local-repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Now you can run your project everywhere without any additional configurations or installations.
If you are having some issue when including dependency for 6.1.0.jre7 from #nirmals answer in https://stackoverflow.com/a/41149866/1570834, in your pom with commons-codec/ azure-keyvault I prefer going with this:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre7</version>
</dependency>
It is not too hard. I have not read the license yet. However I have proven this works. You can copy sqljdbc4 jar file to a network share or local directory. Your build.gradle should look like this :
apply plugin: 'java'
//apply plugin: 'maven'
//apply plugin: 'enhance'
sourceCompatibility = 1.8
version = '1.0'
//library versions
def hibernateVersion='4.3.10.Final'
def microsoftSQLServerJDBCLibVersion='4.0'
def springVersion='2.5.6'
def log4jVersion='1.2.16'
def jbossejbapiVersion='3.0.0.GA'
repositories {
mavenCentral()
maven{url "file://Sharedir/releases"}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile "org.hibernate:hibernate-core:$hibernateVersion"
compile "com.microsoft.sqlserver:sqljdbc4:$microsoftSQLServerJDBCLibVersion"
}
task showMeCache << {
configurations.compile.each { println it }
}
under the sharedir/releases directory, I have directory similar to maven structure which is \sharedir\releases\com\microsoft\sqlserver\sqljdbc4\4.0\sqljdbc4-4.0.jar
good luck.
David Yen
You can use another driver
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
and in xml
<bean id="idNameDb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url" value="jdbc:jtds:sqlserver://[ip]:1433;DatabaseName=[name]" />
<property name="username" value="user" />
<property name="password" value="password" />
</bean>
The com.microsoft.sqlserver package on Maven now only has version 6.0 as the lowest version JDBC. So you need try another groupId Maven which has JDBC version 4.0.
I recommend this; it works for me. I'm using SQL Server 2012 and Java 8.
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
And a config properties file like:
jdbc.driverClassName = net.sourceforge.jtds.jdbc.Driver
jdbc.url = jdbc:jtds:sqlserver://localhost:1433;databasename=YourDB;encrypt=true;trustserverCertificate=true

Jboss RestEasy web service connection pooling

Getting error
NoSuchMethodError: org.apache.http.impl.conn.DefaultClientConnectionOperator.(Lorg/apache/http/conn/scheme/SchemeRegistry;Lorg/apache/http/conn/DnsResolver;)
Using httpclient-4.2-alpha1.jar
Configuration :
<!-- Rest easy connection pooling -->
<bean id="poolingClientConnectionManager" class="com.auction.acp.rest.impl.ConnectionManager" >
</bean>
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient" >
<constructor-arg name="conman" ref="poolingClientConnectionManager"> </constructor-arg>
</bean>
When I explore jar this constructor is already there.
First thing which is coming in my mind is some other library [I'm using JBoss] is in use.
Tried with exclusions in jboss-deployment-structure.xml but no luck.
<exclusions>
<module name="org.apache.httpcomponents" />
<module name="org.apache.http.impl.conn" />
</exclusions>
If the constructor exists in the JAR you're "exploring" but JBoss can't find it, it means JBoss is not using the JAR you want it to. I suggest using Logback for logging, as it'll add the name of the JAR to the stacktrace in your logs so you know which JAR JBoss is using.

Flyway Unable to instantiate jdbc driver

Just starting out with Flyway and Spring 3.0. So far, all I did was add the Flyway dependency and plugin to my pom.xml. Next, I tried running mvn flyway:status in the command line. However, it complains that it is unable to instantiate the jdbc driver (I'm using postgres).
Does anybody know what might be causing this? I'm using Springsource Tool Suite to develop my app. The postgres driver is located under WEB-INF/lib/postgresql-9.1-902.jdbc4.jar
Any help is greatly appreciated! Thanks!
For the Maven plugin to work you must:
Add this dependency to your project (or just the plugin):
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
and configure the plugin like this:
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://...</url>
<user>...</user>
<password>...</password>
</configuration>
</plugin>
You also have to provide the Postgresql jdbc drivers as a maven dependency:
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-902.jdbc4</version>
</dependency>

Resources