Reputation: 505
I'm currently in the process of learning the Play framework, but ran into some trouble pretty quickly.
I've got an independent Java project that uses Hibernate to persist and fetch data from a MySQL database. This project is full of DTOs and DAOs.
I thought it would be a good idea to reference the Hibernate project in my new Play framework project, and consequently take advantage of the different DAOs and DTOs through it.
Everything compiles in Eclipse, but when running my Play application in the browser I get an error that the package com.path.to.hibernate.project.package could not be found.
Is there a secret way to reference other projects in the Play framework or am I simply doing it wrong? I kind of like the idea of separating the Hibernate stuff from the Play framework stuff.
If you think I should be taking a different approach on this, I'm all ears.
Thanks.
EDIT:
build.sbt (equivalent of Build.scala?)
name := "klepp_rc_play"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
"mysql" % "mysql-connector-java" % "5.1.29"
)
play.Project.playJavaSettings
application.conf
...
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/play"
db.default.user=****
db.default.password=****
ebean.default="models.*"
...
conf/META-INF/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="defaultPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
Upvotes: 0
Views: 365
Reputation: 6637
Your question involves some knowledge of sbt
, I wouldn't even say it's just basic stuff. You ideally want your independent project built with sbt
and then referenced from your play application.
Here's what I would do as a start, and then as you progress with sbt
, you could refine this.
A, Build your independent project they way the most comfortable is for you. This may even mean you just export a jar
file from eclipse (yes, some would consider this as an act of the devil, but we just want to kick-start this). But pay attention to all of its dependencies! Then take this jar
and put it in your play application's lib
folder (if there's no such folder, create one). It will be automatically put on the class path. Now you can either put your dependencies into this folder as well, or list them in your build.sbt
.
B, If you built your application with maven, you could reference your project in build.sbt
as usual ("groupId" % "artifactId" % "version"). But you should add your local repository to your build.sbt
. Here's how to do it: SBT doesn't find file in local maven repository although it's there
C, Convert your independent project to an sbt
project, then you can manage its build process easily.
Now if you want to modify your independent project along the way, it's probably worth to go with option C. Otherwise if you just want to start to get to know Play Framework, go with A or B. But you'll need to get to know sbt
as well.
Upvotes: 1