I'm new to Play framework and working on a Java webapp using it. I understand to build play 2.1.1 applications, we need to use SBT.
Questions:
Is this the default build system for Play? Don't we have any Play framework commands which will build, test, resolve dependencies etc?
Can I use Play framework with Maven / Maven repository, or if i need to use SBT only, can I use SBT with Maven repository? Is this a good practice?
I tried installing SBT. Extracted the downloaded zip file and added the <SBT_HOME>\bin directory to Windows path variable. When I execute sbt command, I'm getting the following error:
The system cannot find the file C:\installations\sbt\bin\sbtconfig.txt. java.io.FileNotFoundException: C:\Windows\system32\config\systemprofile\.sbt\boot\update.log (The system cannot find the path specified)
Am I doing anything wrong in the installation?
Is this the default build system for Play?
Yes, sbt is the default build system for Play application.
Can I use Play framework with Maven / Maven repository?
Yes, by default, Play uses Maven2 repository and Typesafe repository. Here's the default resolver:
resolvers ++= Seq(
"Maven Repository" at "http://repo1.maven.org/maven2/",
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)
If you need to find add a dependency, you can simply go to the Maven2 repository.
For example, this is the repository for Google Guice
http://mvnrepository.com/artifact/com.google.code.guice/guice/1.0
You should be able to see a sbt tab, and find the code you need to write in Build.scala
libraryDependencies += "com.google.code.guice" % "guice" % "1.0"
There's no need to install sbt if you have installed play.
Simply cd to your project directory and run play.
Related
I had created a maven project using java .
Now i want to create a maven dependency so that any other can use this dependency in his own sbt project and will be able to access functions of my maven project .
e.g. As we do , if we want to use akka in our sbt project , then we simply write the mvn dependency plugin( "com.typesafe.akka" %% "akka-slf4j" % "2.4.8") for akka in my sbt project . and we can access all those class and functions provided by akka .
Simillarly i want to create some plugins for my maven project .
Please guide me how should i start ?
Thanks in advance.
Once you have compiled and tested your libraries you need to install mvn install it to repository, it can be your company hosted shared repository and any public repository. You should be able configure this repository settings in your pom.xml or settings.xml file.
Once you installed your artifact in a particular repository, your co-worker or any other can access them in java or scala, as long as they have the access to this repository. Typically they will have to specify your repository in there pom xml.
I am writing an application using play 2.2.1 with sbt 0.13.0.
In this application I have a dependency to another project which is a snapshot and to which I also make some modifications. If I build that project it is written to my local Maven repository. But normally that project should be retrieved from a private online Maven repository.
How can I configure sbt to always retrieve the newest version of the snapshot, regardless if it has to be retrieved from my local Maven repository or the online Maven repository.
Till now I added this to my build.sbt:
resolvers += "Online Repo" at "https://online-repo.com/somePath"
resolvers += "Local Maven Repository" at "file:///"+Path.userHome.absolutePath+"/.m2/"
libraryDependencies += "com.some.project" % "a-project" % "2.0-SNAPSHOT"
The problem with this is that the project is retrieved from the first resolver. In this case "Online Repo". Although the Snapshot in "Local Maven Repository" could be newer.
How can I configure sbt to always retrieve the newest version of the
snapshot, regardless if it has to be retrieved from my local Maven
repository or the online Maven repository.
According to Dependency Management Flow:
update resolves dependencies according to the settings in a build
file, such as libraryDependencies and resolvers.
and
Directly running the update task (as opposed to a task that depends on
it) will force resolution to run, whether or not configuration
changed. This should be done in order to refresh remote SNAPSHOT
dependencies.
which means that SBT does this by design.
I have a couple of java projects (Abc.Domain, Abc.Framework etc) and I have recently created a new playframework 2.2.1 java project (Abc.Rest.Api). I am using Eclipse as the IDE (also tried this in IntellijIdea).
The hierarchy of my code base looks like as below
/POC (Empty project)
/Abc.Domain (Java project/module)
/Abc.Framework (Java project/module)
/Abc.Rest.Api (play2 for java project/module)
I would like to access the classes and services of Abc.Domain and Abc.Framework in Abc.Rest.Api. I have tried this by adding Abc.Domain and Abc.Framework projects in Abc.Rest.Api Java Build Path in Eclipse. The project builds fine and I can access all the classes of Abc.Domain and Abc.Framework in Abc.Rest.Api, however when I run or Debug the Abc.Rest.Api the sbt of playframwork is not able to find those classes and relevant imports, resulting in runtime exceptions.
I googled about this problem and the solutions that I found are
Publishing Abc.Domain and Abc.Framework to maven or ivy
repositories and adding them in sbt as follows
libraryDependencies ++= Seq(
"org.apache.derby" % "derby" % "10.4.1.3",
"org.hibernate" % "hibernate-entitymanager" % "3.6.9.Final"
)
create a lib/ directory in the root of your project and then add jar
files to that directory. They will automatically be added to theenter code here
application classpath
By doing either of the above I no longer will have the capability to do realtime debugging and source code navigation to the classes and services of Abc.Domain and Abc.Framework.
I also tried this in IntellijIdea, ironically in IntellijIdea you can not add java modules as dependencies to playframework java module directly.
Please can anyone guide me in the right direction to add java projects as dependencies to my playframework java project without loosing debugging and source code navigation of java projects either by using Eclipse of IntellijIdea
Play framework supports modules. I think you have to create modules for your project in order to access and include them in your codebase.
Other than this I think adding lib is a option but then your source code navigation and change will not work like you want.
Just create 2 jars - one with compilation output, second with sources only, I don't know how it works in Eclipse, anyway in Idea you can just Attach sources if missing for given jar.
You can complete it in 30 seconds (so definitely faster then configuring custom maven repo), sometimes it's required to perform play idea command to force IDE to reindex code of unmanaged dependencies, but finally you have the possibility to read the source code of the modules, debug as required, preview the javadoc for methods, etc, etc.
I am using play 2.2.0 for my application so inorder to host the application i need to create a war file so i can host in my Tomcat7 server. So is there any method to
Clean and Build as we have options in netbeans with console.
Create war file so i can host.
The method to create a war file as in normal jsp hosting i paste all my class files in WEB_INF folder but here how can i do please tell the procedure. I just gave few try this i have mentioned below i know i am wrong please show me the right way.
F:\Play_workspace\ThemePractice>play war
[info] Loading project definition from F:\Play_workspace\ThemePractice\project
[info] Set current project to ThemePractice (in build file:/F:/Play_workspace/Th
emePractice/)
[error] Not a valid command: war (similar: start)
[error] Not a valid project ID: war
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: war (similar: watch, run, apiUrl)
[error] war
[error] ^
There is a plugin for creating a war file, however Play 2.2.x is currently not supported.
Although a branch exists on Github for this feature, it looks like it is still being worked on. You'd have to contact the maintainers for a time line.
Update: It is now possible to create a war file with Play 2.2.x, see Paul D. Eden's comment.
Play 2.1.4 onwards, support for packaging into a war file has been withdrawn. There is a workaround for the same which can help you in generating war file. You fool the compiler and let it think that we are using earlier version of Play. For details refer to the following link :-
Create War from Play 2.2.1 application
It is working till day for me :)
Add addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.2-beta4") to your plugins.sbt
Add the following to your build.sbt
import com.github.play2war.plugin._
libraryDependencies ++= Seq(
"com.github.play2war" % "play2-war_2.9.1" % "0.8.2"
)
Play2WarPlugin.play2WarSettings
Play2WarKeys.servletVersion := "2.5"
Now you can freely use the "play war" command.
I am having a java project with a ant build file, using this ant file i create an ejb of the project and deploy it on the jboss server.
Now I am planning to use maven and convert this existing project which consist of nearly 28-30 jar's in its class path(jars related to ejb3, hibernate, jboss, etc).
I can easily do it using eclipse i.e right click project goto maven and click Conver to Maven.
A pom.xml is generated and the MavenClassPath Container is also added to the project.
Now I want to know how to get rid of those 28-30 jar's present in the lib folder of the project and in the classpath. i.e. I want my pom.xml handle all the dependencies.
Does Maven provide any mechanism to achieve this goal while converting the project or I have to add all of these jar dependencies one by one manually in the pom.xml file.
The intention of doing this is I want to have common maven remote repository where the jars will be stored and each developer machine will point to it through their maven project.
Thanks
I think you're after a repository manager like Nexus (I use Nexus, it seems to be the most popular http://nexus.sonatype.org/ ).
Nexus can be used as:
A proxy repository (for Maven Central, etc)
A repository for your own releases.
Nexus provides user management for your developers to release builds into the repo.
Developers will then point their Maven settings.xml file to your Nexus repository, and all their dependencies will come from here (Nexus will cache them).
I'm afraid you will have to configure the dependencies individually, but that is a good thing, because you should pay attention to what version ranges you are interested in for each dependency.
Any jars which can't be found in Maven Central, etc, you can add to your own Nexus repository .
Ofcourse there are alternatives to Nexus, but I haven't used any.
HTH
The most important thing i can recommend is to use a Maven Repository Manager (Nexus, Artifactory or Achiva or other..).
Second your pom conversion via Eclipse shows me that you are not using an up-to-date Eclipse nor an up-to-date Maven Plugin for Eclipse. The best thing would be use Eclipse-Indigo (m2e is the newest and greatest).
Furthermore you have to go through all your jar's and add them step by step to you pom (dependencies) and see if your project can be compiled. This should be checked on command line not inside Eclipse.
After you got a working pom.xml file put it into your version control and check if you can remove some of your added dependencies based on transitive dependencies. After that you can finally delete your lib folder.