EzDevInfo.com

scalaxb

scalaxb is an XML data binding tool for Scala. scalaxb | XML databinding for Scala

scalaxb and xsd:choice

Using http://scalaxb.org/

  <xsd:complexType name="Address">
    <xsd:choice>
      <xsd:element ref="ExternalAddress" />
      <xsd:element ref="InternalAddress" />
    </xsd:choice>
  </xsd:complexType>


val internalAddrress = InternalAddress(...);  // this works.
val address : Address = internalAddrress;     // error: type mismatch

how do I need to modify this code to make it work?

There is some info here, and I played with DataRecord and others, but I didn't make it work. http://scalaxb.org/narrower-choice


Source: (StackOverflow)

Scalaxb reads from XML, invokes "label", receives UnsupportedOperationException - why?

I'm using scalaxb to convert an instance of XML into another object as follows:

val x = xml.XML.load(inputStream)
println(x)

val ed = scalaxb.fromXML[entityDescriptor.scalaxb.EntityDescriptorType](x)
println(ed)

When it invokes fromXML, I receive the following exception:

scalaxb.ParserFailure: Error while parsing 
    urn:oasis:names:tc:SAML:2.0:protocol 
    urn:oasis:names:tc:SAML:1.1:protocol 
    urn:oasis:names:tc:SAML:1.0:protocol: 
    java.lang.UnsupportedOperationException: 
    class Group does not support method 'label'

The XML is well-formed and valid, according to Java's built-in XML Schema validator (I'm converting from a Java to a Scala project).

From my own investigation, it appears that somewhere in scalaxb, it has created an instance of scala.xml.Group, and it has invoked the label method, which for Group, has no implementation.

  1. Is this a bug, or am I doing something wrong?

  2. If it is a bug, is there a workaround?

  3. If it is not a bug, what am I doing wrong?


Source: (StackOverflow)

Advertisements

Stubbing SOAP requests in Scala

I use scalaxb to generate models and client part of the SOAP interface. For testing I use Betamax, which can also be used in Scala. However, scalaxb uses Netty as a transport, which ignores proxy settings set up by Betamax. How would you cope with this situation?

scalaxb uses cake pattern, so the service is built from 3 parts like in the following example:

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
import scala.concurrent.duration._

val service = (new stockquote.StockQuoteSoap12Bindings with
  scalaxb.SoapClientsAsync with
  scalaxb.DispatchHttpClientsAsync {}).service
val fresponse = service.getQuote(Some("GOOG"))
val response = Await.result(fresponse, 5 seconds)
println(response)

And tests:

import co.freeside.betamax.{TapeMode, Recorder}
import co.freeside.betamax.proxy.jetty.ProxyServer
import dispatch._
import org.scalatest.{Tag, FunSuite}
import scala.concurrent.duration._

import scala.concurrent.{Await, Future}

class StockquoteSpec extends FunSuite with Betamax {

  testWithBetamax("stockquote", Some(TapeMode.READ_WRITE))("stockquote") { 
    val fresponse = service.getQuote(Some("GOOG"))
    val response = Await.result(fresponse, 5 seconds)
    println(response)
  }
}

trait Betamax {

  protected def test(testName: String, testTags: Tag*)(testFun: => Unit)

  def testWithBetamax(tape: String, mode: Option[TapeMode] = None)(testName: String, testTags: Tag*)(testFun: => Unit) = {
    test(testName, testTags: _*) {
      val recorder = new Recorder
      val proxyServer = new ProxyServer(recorder)
      recorder.insertTape(tape)
      recorder.getTape.setMode(mode.getOrElse(recorder.getDefaultMode()))
      proxyServer.start()
      try {
        testFun
      } finally {
        recorder.ejectTape()
        proxyServer.stop()
      }
    }
  }
}

Versions:

  • net.databinder.dispatch 0.11.2
  • co.freeside.betamax 1.1.2
  • com.ning.async-http-client 1.8.10
  • io.netty.netty 3.9.2.Final

Source: (StackOverflow)

scalaxb and multiple groups

Using scalaxb 1.1.2 (http://scalaxb.org) on MusicXML (http://www.musicxml.com/for-developers/), I got the following snippet:

<xs:complexType name="part-list">
    <xs:sequence>
        <xs:group ref="part-group" minOccurs="0" maxOccurs="unbounded"/>
        <xs:group ref="score-part"/>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:group ref="part-group"/>
            <xs:group ref="score-part"/>
        </xs:choice>
    </xs:sequence>
</xs:complexType>

This leads to a illegal inheritance:

  trait DefaultGeneratedPartu45listFormat extends scalaxb.ElemNameParser[generated.Partu45list] 
    with GeneratedPartu45groupGroupFormat 
    with GeneratedScoreu45partGroupFormat 
    with GeneratedPartu45groupGroupFormat {

    ...    
  }

As you can see, the double inheritance of GeneratedPartu45groupGroupFormat will make the compile unhappy.

So I have two questions:

  1. Is there a way to workaround this issue by changing the XSD to something equivalent that scalaxb understands?

  2. Is there a way to caonfigure scalaxb to handle that issue gratefully?


Source: (StackOverflow)

combining scalaxb with scalacheck

I wonder how I could make use of scalacheck on types generated by scalaxb stemming from complex xsds like this one:

http://wiki.xmldation.com/@api/deki/files/379/=pain.001.001.03.xsd

The actual documents resemble payments and I want to restrict the test-data in the one or other way (account owners/numbers, amounts, countries).

the actual components to test are: xml-parsers checking the syntax and producing error-messages, xml-parsers parsing the documents to a record-like data-structure, xml-printers writing such documents.

Would it be feasible ?


Source: (StackOverflow)

Simple ScalaXB example causes NoSuchMethodError in Dispatch

I am new to Scala and I was trying out an example with ScalaXB.

I am using IntelliJ IDEA and the latest Scala version 2.10.1.

ScalaXB uses Dispatch so I added that (version 0.9.5) as a dependency to the project. I also had to add as a dependency slf4j-nop:1.6.2. So, afterwards everything compiled but an exception keeps appearing:

Exception in thread "main" java.lang.NoSuchMethodError: scala.util.control.Exception$Catch.either(Lscala/Function0;)Lscala/Either;
at dispatch.Promise$class.result(promise.scala:64)
at dispatch.ListenableFuturePromise.result(promise.scala:223)
at dispatch.Promise$class.apply(promise.scala:75)
at dispatch.ListenableFuturePromise.apply(promise.scala:223)
at scalaxb.DispatchHttpClients$DispatchHttpClient$class.request(httpclients_dispatch.scala:12)
at scalaxb.DispatchHttpClients$$anon$1.request(httpclients_dispatch.scala:4)
at scalaxb.SoapClients$SoapClient$class.soapRequest(soap12.scala:32)
at scalaxb.SoapClients$$anon$1.soapRequest(soap12.scala:14)
at scalaxb.SoapClients$SoapClient$class.requestResponse(soap12.scala:51)
at scalaxb.SoapClients$$anon$1.requestResponse(soap12.scala:14)
at eu.getintheloop.sample.XMLProtocol$WeatherSoap12Bindings$WeatherSoap12Binding$class.getWeather(xmlprotocol.scala:53)
at eu.getintheloop.sample.XMLProtocol$WeatherSoap12Bindings$$anon$3.getWeather(xmlprotocol.scala:48)
at eu.getintheloop.sample.main$.main(main.scala:20)
at eu.getintheloop.sample.main.main(main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

The code line is:

protected lazy val result = allCatch.either { claim }

This looks quite strange because "claim" appears to be a perfectly good java.lang.String object:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWeatherResponse xmlns="http://litwinconsulting.com/webservices/">
<GetWeatherResult>Sunny</GetWeatherResult>
</GetWeatherResponse>
</soap:Body>
</soap:Envelope>

Any ideas what has gone wrong?


Source: (StackOverflow)

multiple versions handling in scalaxb

I have different versions of a XSD using the same namespace. They differ by the version attribute:

<xs:schema xmlns="http://mynamespace/2014" version="1.3.0">
<xs:schema xmlns="http://mynamespace/2014" version="2.0.0">

How to handle different XSD versions with scalaxb in sbt? How to have one package per version?


Source: (StackOverflow)

Errors with using Scalaxb for code generation

I had to fiddle with a WSDL document for one of the implementations and I came across Scalaxb! I'm now trying to generate some scala classes from the WSDL file that I have and as expected I'm hitting into some issues:

Here is a snippet of the WSDL file:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:tns="http://www.myservice.com/MyServices/2012/06/18/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
 xmlns:s="http://www.w3.org/2001/XMLSchema"
 name="MyServices"
 targetNamespace="http://www.myservice.com/MyServices/2012/06/18/">
<wsdl:types>
 <s:schema elementFormDefault="qualified" targetNamespace="http://www.myservice.com/MyServices/2012/06/18/">
  <s:complexType name="UserCredentials">
   <s:sequence>
    <s:element name="UserName" type="s:string" />
    <s:element name="Password" type="s:string" />
   </s:sequence>
  </s:complexType>
  <s:element name="UserCredentials" type="tns:UserCredentials" />
  <s:complexType name="AnotherComplexType" >
   <s:sequence>
    <s:element name="Index" type="s:int" />
    <s:element name="Name" type="s:string" />
    <s:element name="Status" type="s:boolean" />
   </s:sequence>
  </s:complexType>
  ....

Assume that the rest of the WSDL file is completely fine, when I tried to compile the project, I hit the following error:

[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1542: not found: value userCredentials
[error]             scalaxb.toXML(userCredentials, Some("http://www.myservice.com/MyServices/2012/06/18/"), "UserCredentials", defaultScope), defaultScope, baseAddress, "POST", Some(new java.net.URI("http://1.1.1.1/cgi-bin/cgi.cgi?WebService=SetGPTimerChannel"))).transform({ case (header, body) => 
[error]                           ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1544: value toSeq is not a member of Any
[error]               scala.xml.Elem(null, "Body", scala.xml.Null, defaultScope, true, body.toSeq: _*)
[error]                                                                                     ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1551: not found: value userCredentials
[error]             scalaxb.toXML(userCredentials, Some("http://www.myservice.com/MyServices/2012/06/18/"), "UserCredentials", defaultScope), defaultScope, baseAddress, "POST", Some(new java.net.URI("http://1.1.1.1/cgi-bin/cgi.cgi?WebService=SomeServiceCall"))).transform({ case (header, body) => 
[error]                           ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1553: value toSeq is not a member of Any
[error]               scala.xml.Elem(null, "Body", scala.xml.Null, defaultScope, true, body.toSeq: _*)
[error]                                                                                     ^

Any ideas what and why I'm facing this issue? Here is my build.sbt:

import ScalaxbKeys._

val scalaXml = "org.scala-lang.modules" %% "scala-xml" % "1.0.2"
val scalaParser = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.1"
val dispatchV = "0.11.1" // change this to appropriate dispatch version
val dispatch = "net.databinder.dispatch" %% "dispatch-core" % dispatchV

organization := "com.eon"

name := "scalaxb-myservice-sample"

scalaVersion := "2.11.6"

scalaxbSettings

packageName in (Compile, scalaxb) := "rdmservice"

dispatchVersion in (Compile, scalaxb) := dispatchV

async in (Compile, scalaxb) := true

sourceGenerators in Compile <+= scalaxb in Compile

libraryDependencies ++= Seq(scalaXml, scalaParser, dispatch)

Source: (StackOverflow)

Scala: How to remove a duplicate attribute?

In scalaxb I have an element with duplicates:

xsi:type="ObjectEventType" xsi:type="ObjectEventType"

When duplicates exist how do I traverse the tree and transform to a new tree removing the duplicates?


Source: (StackOverflow)

Implement a SOAP webservice in scala

What is the best library/framework to implement a SOAP webservice in scala?

an example of using scalaxb to implement a SOAP webservice?

Please, no heavy frameworks such as lift.


Source: (StackOverflow)

scalaxb: ConnectException: Worker has already been shutdown

After updating my Scala SOAP client code to the most recent scalaxb (1.2.1) and switching to Features (instead of Eithers), I'm getting a ConnectException: Worker has already been shutdown when making a simple SOAP request:

val service = (new aw.ServicesSOAPBindings with Soap11ClientsAsync with scalaxb.DispatchHttpClientsAsync {}).service

// list providers
service.listProviders(4) onComplete { 
  case Success(respond) => 
    println(s"Respond: code ${respond.ErrorCode}, messsage: ${respond.ErrorMessage}, Providers: ${respond.Providers.size}")
    if (!respond.Providers.isEmpty)
      listKnownProviders(respond.Providers)

  case Failure(failure) => println("Failure I : " + failure.printStackTrace())
}

Am I missing any Netty/Dispatch configuration steps?

Here is the stacktrace:

java.util.concurrent.ExecutionException: java.net.ConnectException: Worker has already been shutdown to https://service.xxxxxxx.com/wsdl/v4/
    at com.ning.http.client.providers.netty.NettyResponseFuture.abort(NettyResponseFuture.java:342)
    at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:107)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)
    at org.jboss.netty.channel.DefaultChannelFuture.addListener(DefaultChannelFuture.java:145)
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect(NettyAsyncHttpProvider.java:1136)
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(NettyAsyncHttpProvider.java:937)
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.nextRequest(NettyAsyncHttpProvider.java:1397)
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.nextRequest(NettyAsyncHttpProvider.java:1393)
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.remotelyClosed(NettyAsyncHttpProvider.java:1514)
    at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:95)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:418)
    at org.jboss.netty.channel.DefaultChannelFuture.setFailure(DefaultChannelFuture.java:380)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$1.operationComplete(NioClientSocketPipelineSink.java:115)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:413)
    at org.jboss.netty.channel.DefaultChannelFuture.setSuccess(DefaultChannelFuture.java:362)
    at org.jboss.netty.channel.AbstractChannel$ChannelCloseFuture.setClosed(AbstractChannel.java:355)
    at org.jboss.netty.channel.AbstractChannel.setClosed(AbstractChannel.java:185)
    at org.jboss.netty.channel.socket.nio.AbstractNioChannel.setClosed(AbstractNioChannel.java:197)
    at org.jboss.netty.channel.socket.nio.NioSocketChannel.setClosed(NioSocketChannel.java:84)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.close(AbstractNioWorker.java:356)
    at org.jboss.netty.channel.socket.nio.NioClientBoss.close(NioClientBoss.java:167)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:306)
    at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)

Thanks in advance for any hints.


Source: (StackOverflow)

Creating Dataframe from XML parsed by scalaxb

I can successfully parse XML data dropped into a directory by using the Spark streaming fileStream method, and I can write the resulting RDDs out to a text file just fine:

val fStream = {
  ssc.fileStream[LongWritable, Text, XmlInputFormat](
    WATCHDIR, xmlFilter _, newFilesOnly = false, conf = hadoopConf)
}


fStream.foreachRDD(rdd =>
  if (rdd.count() == 0) {
    logger.info("No files..")
  })

val dStream = fStream.map{ case(x, y) =>
  logger.info("Hello from the dStream")
  logger.info(y.toString)
  scalaxb.fromXML[Music](scala.xml.XML.loadString(y.toString))
}

dStream.foreachRDD(rdd => rdd.saveAsTextFile("file:///tmp/xmlout"))

The trouble is when I want to convert the RDDs to DataFrames in order to either register them as a temp table or saveAsParquetFile.

This code:

val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
dStream.foreachRDD(rdd => rdd.distinct().toDF().printSchema())

Results in this error:

java.lang.UnsupportedOperationException: Schema for type scalaxb.DataRecord[scala.Any] is not supported

I would have thought that since scalaxb generates case classes for my records, and that it would be simple for Spark to infer using reflection, and I see this is what it's trying to do, except Spark doesn't support the scalaxb.DataRecord type. Are there any Spark or Scalaxb experts who have any ideas on how to make the case classes generated by Scalaxb compatible with Spark?

BTW, here are the generated classes from scalaxb:

package generated

case class Song(attributes: Map[String, scalaxb.DataRecord[Any]] = Map()) {
  lazy val title = attributes.get("@title") map { _.as[String] }
  lazy val length = attributes.get("@length") map { _.as[String] }
}

case class Album(song: Seq[generated.Song] = Nil,
  description: String,
  attributes: Map[String, scalaxb.DataRecord[Any]] = Map()) {
  lazy val title = attributes.get("@title") map { _.as[String] }
}

case class Artist(album: Seq[generated.Album] = Nil,
  attributes: Map[String, scalaxb.DataRecord[Any]] = Map()) {
  lazy val name = attributes.get("@name") map { _.as[String] }
}

case class Music(artist: Seq[generated.Artist] = Nil)

Source: (StackOverflow)

scalaxb generated code causes stack overflow during compilation

I'm using scalaxb to generate Scala code from an XSD. (In particular I am using the maven scalaxb plugin.) The code generation phase runs without a hitch, and eyeballing them, the generated scala files look good. But when I try to compile I am getting a stack overflow on:

[ERROR] error: java.lang.StackOverflowError
[INFO]  at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:754)
[INFO]  at scala.tools.nsc.matching.MatrixAdditions$MatchMatrixOptimizer$lxtt$2$.transform(MatrixAdditions.scala:113)
[INFO]  at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:845)
[INFO]  at scala.tools.nsc.matching.MatrixAdditions$MatchMatrixOptimizer$lxtt$2$.transform(MatrixAdditions.scala:113)
[INFO]  at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:837)
[INFO]  at scala.tools.nsc.matching.MatrixAdditions$MatchMatrixOptimizer$lxtt$2$.transform(MatrixAdditions.scala:113)
[INFO]  at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:821)
[INFO]  at scala.tools.nsc.matching.MatrixAdditions$MatchMatrixOptimizer$lxtt$2$.transform(MatrixAdditions.scala:113)
[INFO]  at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:821)
[INFO]  at scala.tools.nsc.matching.MatrixAdditions$MatchMatrixOptimizer$lxtt$2$.transform(MatrixAdditions.scala:113)
[INFO]  at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:821)
[INFO]  at scala.tools.nsc.matching.MatrixAdditions$MatchMatrixOptimizer$lxtt$2$.transform(MatrixAdditions.scala:113)

...

[INFO]  at scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:311)
[INFO]  at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:294)
[INFO]  at scala.tools.nsc.transform.ExplicitOuter$Phase.run(ExplicitOuter.scala:539)
[INFO]  at scala.tools.nsc.Global$Run.compileSources(Global.scala:949)
[INFO]  at scala.tools.nsc.Global$Run.compile(Global.scala:1034)
[INFO]  at scala.tools.nsc.Main$.process(Main.scala:106)
[INFO]  at scala.tools.nsc.Main$.main(Main.scala:123)
[INFO]  at scala.tools.nsc.Main.main(Main.scala)
[INFO]  ... 6 more
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------

The xsd I am using has been tested and works with jaxb.

Scala version is 2.9.0-1, scalaxb is 0.6.2.


Source: (StackOverflow)

Scala future app terminates before complete

Just trying to get my first futures use up and running and doing a test similar to an example outlined in the Akka in Action MEAP book. I want to call a web service and return the result in a future. I am using scalaxb to access the web service. I have outlined the code below but when I run it the app terminates without waiting for the response from the service. Maybe someone can tell me what I am missing?

import scala.util._
import control.NonFatal
import scala.concurrent._
import ExecutionContext.Implicits.global

object Test {


    val service = (new MyServiceBindings with scalaxb.Soap11Clients with scalaxb.DispatchHttpClients {}).service

    def test = {

        val f = future {

            service.someCall() match {
                case Right(resp) => resp
                case Left(fault) => throw new Exception("Fault: " + fault)}
            }
        }

        f.onComplete {
            case Success(resp) => println("Resp: " + resp)
            case Failure(NonFatal(e)) => println("Fail: " + e)
        }
    }

    def main(args: Array[String]): Unit = {
        test
    }
}

Source: (StackOverflow)

Change output directory of sbt

I want to change my output directory for some generated files, in this case generated objects from an XSD-Schema.

Here is part of my Build file.

val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA,
      settings = Defaults.defaultSettings ++ buildInfoSettings ++ scalaxbSettings
    ).settings(
      sourceGenerators in Compile <+= buildInfo,
      buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
      buildInfoPackage := "hello",
      packageName in scalaxb in Compile := "models",
      sourceGenerators in Compile <+= scalaxb in Compile
    )

This code puts my generated files into the below directory:

target/scala-2.10/src_managed/main/models/

How can I change my buildfile to output the files to below instead?

/app/models/

Source: (StackOverflow)