What is the Main class in a Lagom/Play application? - scala

I'm trying to figure out how to package and deploy my lagom app in production. The docs are surprisingly coy about how to actually do this, and when I try to use sbt-native-packager to run universal:packageBin I get the warning that You have no main class in your project. No start script will be generated.
Has anyone worked through this and knows a good tutorial or something to reference?

https://github.com/lagom/lagom/blob/a35fab1ad8a0c4a3d28d6c86ae31a2408da2e340/dev/sbt-plugin/src/main/scala/com/lightbend/lagom/sbt/LagomSettings.scala#L28
Adding that to your project will fix it. That said, generally you shouldn't see this warning, because the Lagom plugin should configure it for you. There's two reasons that I can think of off the top of my head why you might be seeing this warning.
The first would be that you don't have the Lagom plugin enabled on your project. If that's the case, and you're not doing something advanced where you really know what you're doing (and if you really knew what you were doing I would be surprised if you had to ask this question), then you probably have a misconfiguration and need to enable the Lagom plugin.
The second might be that you're running universal:packageBin on multiple projects, some of which do have the Lagom plugin enabled, and some of which don't. In such a case, you probably only want to build the production artifact for your Lagom project, not for all the other projects (eg the API project, or the root project). So, just run it for your service (eg, run my-service-impl/universal:packageBin).

Related

Build vs Deploy vs Publish (Eclipse IDE)

I'm a newbie to J2ee though not a complete newbie. I'm unable to find a good resource (book or video) that could help me understand what exactly happens when we build, deploy and publish. I have a fair idea though. So my questions are -
Is there a good resource out there that can help me understand these concepts? I've read some books on struts and servlets/jsp but they don't delve into eclipse and how/what it does. The eclipse documentation has been helpful but only slightly.
When we build an application the the java files are converted into the class files and stored in the java build path. What else happens during build? Many people use the term 'library dependencies', what does this mean? Also, when people refer to dependencies do they refer to files like xml and tld?
At what stage (build or run on server) does the container check to see if the dependencies are alright? Say for instance, if the servlet class/name in the web.xml file.
Is it appropriate to say that build is basically compilation while deploying the project and running it is the same as executing it?
Familiarity with the servlet specification would help you (perhaps some older version would be quicker to read like 2.4), but general understanding of what you build and how you do it in Eclipse is what you are after.
The way I see it is that during the build Eclipse creates almost complete version of WAR (or some other archive, if you use EJBs for instance) and by publishing you deploy it to some server (this is practically the same thing although Eclipse might just configure the server to use exploded WAR that it just prepared instead of copying it to some "deploy" dir that you are supposed to do if you work without an IDE).
If you configure your project well, the build can only mean compilation, but if you have more ceremony in it, then some source generation and moving files around might happen too.
To address your second question, library dependencies can be files that reside in WEB-INF/lib for instance. Read the spec to know what should be there and what should not. Eclipse tries to copy there all defined dependencies of your project.

Publish Site using SBT

I have an SBT project using SBT 0.13.2. I am using the awesome sbt-site plugin to generate a pamflet site.
What is the best way using SBT to get the generated sbt-site onto a remote server for others to access?
We have this already setup and working wonderfully using Maven and WEBDAV.
I am hoping that there is a simple answer, barring creating my own sbt tasks.
I had to create my own SBT WEBDAV plugin to do the publishing. If people are interested in what I did, feel free to contact me (note: unclear on how to post contact info on here).
It wasn't hard, but rather a pain. I would love to open source it, but that would take time I don't have presently :(

Are there disadvantages to setting up unit or integration tests in Eclipse as a separate project?

I'm currently working on a project using Eclipse where the unit and integration tests are in one project that also contains the DAO and service layer, and there is another project that includes the Web interface. The Web interface contains the Spring configuration files, and instead of duplicating them for the tests in the DAO project, I want to reference the ones that already exist. However, as I started thinking about it, if this is possible, why not just move them into their own project completely and setup project dependencies. Has anyone done this, and do you have an example of this setup, or can you provide some roadblocks you encountered?
I went ahead with this approach, and it doesn't appear to be causing any issues so far. One of our projects has a (classpath) dependency on the other, but the third test project is able to manage that with some setup and configuration.

ant deployment issues

i am looking to make our deployments here not suck and i need some help, if you can help me with these few things i owe you beer
right now whenever i make a change thats not to the jsps i need to clean-including-tomcat otherwise my change doesnt take. this is really annoying.
any clues as to what i can change to make it work?
my current build is really simple, just the regular old, javac, war, deploy
one thing that isnt done is that there is no build dir, the project itself contains a web-inf and the javac is done in place, then the war excludes all the .java resources and wars the project.
edit:
I am looking to fix this problem with least amount of effort - so while switching to maven and learning how to use it might solve this problem, but it will create another problem ;)
You've already identified some of the weaknesses, in your current build.
The easiest way that I can suggest to clean it up would be to start with the directory structure.
I highly recommend using the maven directory structure, I would go further to suggest using maven as a build tool instead of ant, however for some folk that remains open for debate.
The maven directory structure has been well thought out, I really like working on projects that use the maven directory structure, because they follow a convention that allows me to save a lot of time, by knowing from previous experience where to find the application components
java source
unit test source
resources etc.
Also by following the convention, the maven plugins work with less configuration required.
Another useful advantage that I get from working on maven based projects is good code metrics, to measure the health of the application. There are various report available as maven plugins, which will give you new insight into your codebase, including:
checkstyle
pmd
findbugs
and more.
Created a build directory where everything got copied before build
Added some flags to not copy over things that rarely change, like images (also to not remove them on clean)
Started using ant-reload task after deploying code
Now i don't need to restart tomcat on every build, and build takes much less time.

Set up an Eclipse Dynamic Web Project referencing another project

I've got a simple Dynamic Web project set up in Eclipse 3.6 Helios, but am having trouble getting it to make use of the code in another project that I've got.
I've added a reference to my other project to the build path of my web project, and I've got no problems in terms of compiling, only in terms of deploying and testing the result. The built web application doesn't have a jar in the WEB-INF/lib directory, so fair enough it can't find the code. The question is how I set this up. I've looked through the help that I can find and googled a bit but can't find anything obvious that helps out.
How do I set up my web project so that on deploying it it magically has the code from my dependent project inside it?
Thanks.
Note: Ideally I'd like a solution that doesn't involve setting up some kind of build tool. The web project deploys itself without recourse to any build tool (or at least none visible to end user), so was rather hoping that a references project could be integrated into that easily.
What goes in the deployment is determined not by the build path but by the Deployment Assembly entry in Preferences for the dynamic web project.
Use some build tool like ANT or Ivy or Maven that, on build, copies all the dependencies to WEB-INF/lib
Using a build tool is a good practice to automate build, test and deployment. You may also be interested in plug-ins like Maven Reactor.