问题
This is a follow-on question from How to un/marshall underscored XML to/from camelcased Java using JAXB?
I'm trying to use Moxy (part of EclipseLink) from Scala (sbt 0.10.0), and am struggling to figure out how to import and use it. To break this into two parts:
1. Importing Moxy
For once I can't find anything appropriate on mvnrepository.com. From reading this page on Maven setup, I was hoping the following would work:
// /project/Dependencies.scala
object Dependencies {
val resolutionRepos = Seq(
ScalaToolsSnapshots,
"EclipseLink Repo" at "http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo"
)
object V {
val moxy = "2.1.0"
}
object Runtime {
// We use Moxy for the naming convention transforms
val moxy = "org.eclipse.persistence" % "javax.eclipselink" % V.moxy
}
But sbt is complaining module not found: org.eclipse.persistence#javax.eclipselink;2.1.0
2. Specifying Moxy as my JAXB provider
With the above fixed (thanks S.R.I.!) the next problem is that I'm having trouble specifying Moxy as my JAXB provider. From the instructions in this article by Blaise Doughan, it looks like I need to put a jaxb.properties
file with the following entry in the same package as my representations:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
But unfortunately this doesn't seem to be picked up when running through sbt. Any ideas?
Any help gratefully received. And Merry Christmas everybody!
回答1:
CAVEAT: I'm not very familiar with SBT syntax
That said, your issue looks like a problem of loading resources from sbt. Normally, you have properties files, images and other related items in the resources folder in your projects(sbt or maven - more since sbt follows maven project structure). Since jaxb.properties needs to be in the same package as your JAXB representation classes, you'll need to configure sbt to look for this in your src folders. Have a look at this page, particularly the section on unmanaged vs managed dependencies.
Alternatively, this SO page talks about the resources problem. Hope this answers your question. :)
EDIT
Another thing you can consider is, since non source project components are automatically picked up by sbt from the resources
folder - you can simply place your jaxb.properties in the resources
directory replicating the path as in src
folders. For example, if your JAXB representation lies in the package com.foo.bar.baz
in the src
directory, you could replicate the structure in resources
as in src/main/resources/com/foo/bar/baz
and place your properties file there. I believe it would be loaded into classpath by sbt
.
来源:https://stackoverflow.com/questions/8629025/how-do-i-use-moxy-from-scala