Created
March 19, 2012 12:29
-
-
Save danielberndt/2110191 to your computer and use it in GitHub Desktop.
Build.scala to fix classnotfoundexception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import Keys._ | |
import PlayProject._ | |
object ApplicationBuild extends Build { | |
val appName = "project" | |
val appVersion = "1.0" | |
val appDependencies = Seq( | |
"mysql" % "mysql-connector-java" % "5.1.18" | |
) | |
val PostCompile1 = (sourceDirectory in Compile, dependencyClasspath in Compile, compile in Compile, javaSource in Compile, sourceManaged in Compile, classDirectory in Compile, ebeanEnabled, streams) map { | |
(src, deps, analysis, javaSrc, srcManaged, classes, ebean, s) => | |
s.log.info("PostCompile1") | |
// Properties | |
val classpath = (deps.map(_.data.getAbsolutePath).toArray :+ classes.getAbsolutePath).mkString(java.io.File.pathSeparator) | |
val javaClasses = (javaSrc ** "*.java").get.map { sourceFile => | |
analysis.relations.products(sourceFile) | |
}.flatten.distinct | |
javaClasses.foreach(play.core.enhancers.PropertiesEnhancer.generateAccessors(classpath, _)) | |
javaClasses.foreach(play.core.enhancers.PropertiesEnhancer.rewriteAccess(classpath, _)) | |
s.log.info("ebean="+ebean) | |
// EBean | |
if (ebean) { | |
try { | |
s.log.info("in ebean") | |
val cp = deps.map(_.data.toURI.toURL).toArray :+ classes.toURI.toURL | |
s.log.info("cp calced") | |
import com.avaje.ebean.enhance.agent._ | |
import com.avaje.ebean.enhance.ant._ | |
import collection.JavaConverters._ | |
import com.typesafe.config._ | |
val cl = ClassLoader.getSystemClassLoader | |
val t = new Transformer(cp, "debug=10") | |
s.log.info("transformer created") | |
val ft = new OfflineFileTransform(t, cl, classes.getAbsolutePath, classes.getAbsolutePath) | |
s.log.info("oft created") | |
//model definition only can come from bundled application.conf at this point and "conf" folder is not visible as a resource from this classloader, so | |
s.log.info("conf exists: "+new File("conf/application.conf").exists()) | |
val models = try { | |
val config = ConfigFactory.load(ConfigFactory.parseFileAnySyntax(new File("conf/application.conf"))) | |
s.log.info("config loaded") | |
config.getConfig("ebean").entrySet.asScala.map(_.getValue.unwrapped).toSet.mkString(",") | |
} catch { case _ => "models.*" } | |
s.log.info("before enhance:"+models) | |
ft.process(models) | |
s.log.info("after enhance") | |
} catch { | |
case _ => | |
s.log.info("error happened!") | |
} | |
} | |
// Copy managed classes | |
val managedClassesDirectory = classes.getParentFile / (classes.getName + "_managed") | |
val managedClasses = ((srcManaged ** "*.scala").get ++ (srcManaged ** "*.java").get).map { managedSourceFile => | |
analysis.relations.products(managedSourceFile) | |
}.flatten x rebase(classes, managedClassesDirectory) | |
// Copy modified class files | |
val managedSet = IO.copy(managedClasses) | |
// Remove deleted class files | |
(managedClassesDirectory ** "*.class").get.filterNot(managedSet.contains(_)).foreach(_.delete()) | |
analysis | |
} | |
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings( | |
templatesImport += "controllers.tmp._", compile in (Compile) <<= PostCompile1 | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment