Sharing source/libraries between sbt and Scala play framework - scala

I have two related apps I am developing in Scala. One is a server-side processing engine built using SBT and running headlessly doing some number crunching (on a cron job). The other is a web site written in Scala and running on the play framework.
I have code that I would like to be able to share between the two, but as each of them (SBT and Play) has their own ideas about directory structure and how to build things it's pretty unclear to me how I should do this. I'd hate to copy and paste the .scala files - but I'm also not keen on using sym links and having them both build from the same files.
If it were possible, I would accept getting the Play scripts to run SBT to build libraries as required. If it were the only way then I would also be OK with using SBT to build jars for Play and then copying them into place. But I'm often developing both simultaneously (they are parts of a bigger app) and it would all work much more smoothly if they updated together. Is this even possible, or if there's another simpler technique I'm missing?
Thanks, Alex

The only easy way is to build JARs with SBT and make Play use them.
On how to copy, you have 2 options:
You manually build and copy them over to the libs folder in Play (you can script that to make it less annoying)
You use a custom repository for your JARs (ala Nexus repository) and use Play dependencies.yml to point to that repo and update. With this you would also need to run play sync --deps often and to tweak the versions, so I'm not sure if it makes too much sense during dev (it makes more sense once the JARs are complete though)

Related

JavaFX program to JAR, been trying to do this for days

Can anyone help me convert this javaFX application into an actual application using JAR, becuase ive been trying to convert it to a JAR for days and it just comes up with error after error. I just want to make an exe but i know how to do that, the JAR ive been trying to make and it makes it, but it never runs, just errors, a million of them.
Here's my github repo https://github.com/Amarnath-someperson/JavaFX-Physics-App with the code in JavaFX-Physics-App/PhysicsApp/src/main/java/com/example/physicsapp/
Creating jars for JavaFX apps is not well supported and you just should not do it. Instead look here https://stackoverflow.com/tags/javafx/info in the Packaging section and create a real app bundle and installer.
I recommend taking a look at this Github repo: https://github.com/wiverson/maven-jpackage-template
It contains a working projekt using Maven, JavaFX 17 and Java 17. Running maven install creates an installer and a runnable exe file. As soon as you get it running, making the necessary changes for your project should not be too difficult.
Asking others to do the complete work for you probably is a bit too much in my opinion. You will need to get a basic understanding of how the packaging works to maintain your project anyway, so I hope this is enough to get you started.
Packaging your application as jar is only useful up to Java(FX) 8, since JavaFX is not included in most JREs after that. So, while it is easy to create the jar, non-developers won't be able to run it.

How Can Play and Jrebel Work Together?

Play recompiles files for you automatically after changes have been made and the browser refreshed. This makes Jrebel unnecessary for Play.
Our flagship product JRebel lets you change your application code and
just hit refresh in your browser and you’ll see the changes instantly.
Play! framework offers something similar. I have not read enough
source code but it seems that with custom extra metadata (see your
app’s tmp/bytecode/DEV), a stateless model and the custom runner (play
run) they will give you the power of changing code on the fly. If they
don’t support the change they will restart your app automatically for
you.
http://zeroturnaround.com/rebellabs/my-top-5-play-framework-features/
However, if you include a library in the Play project that you are making chages to then Jrebel can come in handy so those changes are auto-compiled.
Should Jrebel be included in the Play project or in the library? What would be the simplest workflow?
Easiest way to include JRebel in any project is to follow quickstart guide http://zeroturnaround.com/software/jrebel/quickstart/eclipse/
Most importantly there are 3 parts.
Download JRebel and activate license
Generate rebel.xml config file into library .jar files
Run the play process with jrebel.jar javaagent
After that JRebel will monitor changes in folders defined in rebel.xml and it will reload changes to the .jar library that you are developing.

What is Scala's Simple Build Tool (sbt) and why is it used?

I am new in Scala and I have to learn Scala and SBT, I read the sbt tutorial but i am unable to understand the use of sbt, for what purpose its been used.After reading this tutorial
I am still confused can any one will explain it in simple words, also suggest me if there is some tutorial for simple build tool
When you write small programs that consist of only one, or just two or three source files, then it's easy enough to compile those source files by typing scalac MyProgram.scala in the command line.
But when you start working on a bigger project with dozens or maybe even hundreds of source files, then it becomes too tedious to compile all those source files manually. You will then want to use a build tool to manage compiling all those source files.
sbt is such a tool. There are other tools too, some other well-known build tools that come from the Java world are Ant and Maven.
How it works is that you create a project file that describes what your project looks like; when you use sbt, this file will be called build.sbt. That file lists all the source files your project consists of, along with other information about your project. Sbt will read the file and then it knows what to do to compile the complete project.
Besides managing your project, some build tools, including sbt, can automatically manage dependencies for you. This means that if you need to use some libraries written by others, sbt can automatically download the right versions of those libraries and include them in your project for you.

Project on Google go, imports of libraries

everyone.
I am new to Go language and currently I am trying to understand the basics of building Go applications. I met the following problem.
For example, I am using other libraries in my project. I have them locally, on my computer, so my project works fine.
I am loading my code on github and another programmer download it. As I understand, my code won't work, because this programmer doesn't have the libraries I used.
So the question is: What is the best way to share my project with all libraries it has? Should I upload these libraries in the separate repositories? Then to use my project, people need to look inside the code to detect which libraries I am using to download them one by one?
For example, in Java there is such thing like Maven or Ant, which downloads all required dependencies. Is there any tools like this for Go?
Let's call the main file of my project main.go
And I am using my own library: mathutil.go
what is the best way to make this project run on other computers?
Go's dependencies work very much like using Maven or IVY transitive dependencies. When someone does "go get" of your package, anything you depend on will automatically download.
For example, in your source:
import "github.com/foo/bar"
go will automatically download that to your $GOPATH/src/github.com/foo/bar along with your code.
Assuming the third party libs you use are hosted in a public repo (ie: github) then people don't need to do anything.
If the libraries you used are not available on a public repo, you will need to post them somewhere assuming their licensing allows.
Take a look at golang.org/doc/code.html for more details

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.