View exact java commands issued by SBT - java

I'm trying to integrate jrebel with an SBT project. The following entry is in the build.scala file:
javaOptions ++= Seq("-javaagent:/path/to/jrebel.jar", "-Drebel.log=true", "-Drebel.log.file=/path/to/jrebel.log")
However, I'm not seeing any Jrebel output when SBT is started (or, for that matter, when files are updated) so I'd like to know if there is an SBT command/switch that can used to display the exact java commands that SBT is issuing? (maybe it's a versioning-format difference? I'm using SBT version 0.12.2)

You did something strange.
If you wish to add jrebel to SBT you must add javaagent parameter to your command that invoke sbt-launch.jar Also don't forget properties file. ??? Your Build.scala is so huge? Incredible.
If you with to add jrebel to Scala application then SBT out of scope at all. Just start you app somewhere and it will reload recompiled classes. You need only specify where compiled class files is located. Then use sbt > ~package-bin. It is like maven, ant or any other build system.
IMHO javaOptions affect only specific tasks that fork jvm - like compilation, tests and so on.

Related

Is it possible to package a portable maven in the project (and some general direction on how)?

The solution which needs bootstrapping is supplied as java code. Absolutely sure that this is necessary.
Receivers of the solution are guaranteed to have a suitable JDK
However, receivers of the solution are unable to install Maven (they don't know how to and cannot be taught)
My idea is to include some sort of Maven with the project, such that can be set up in a script like so:
set up maven repo as a folder under the solution folder (using relative reference)
set up anything else maven needs (don't know what, exactly)
call /path/to/maven/mvn compile -f /path/to/oneAndOnly/pom.xml
java /target/MySolutionClas
I am aware of: https://dzone.com/articles/embedding-maven but it gets confusing when he talks about configuring the portable maven into the pom.xml - wait, how is that pom.xml going to mean anything if maven is not configured yet?
(PS: I mean no disrespect to the author. I probably got it all wrong)
One could include a shell script that would setup maven if it is not already present.
The same for building and packaging encapsulating the complexities of the setup to just runing a couple of scripts.
Maven Wrapper aims to do just that, similar to the gradle wrapper seen in many gradle projects.
Running the wrapper goal of the maven wrapper plugin will generate a mvnw script in your project that can be run in place of a globally installed mvn command.
It's part of the maven 3.7.0 release, and documented more fully here: https://maven.apache.org/plugins/maven-wrapper-plugin/index.html
See https://github.com/takari/maven-wrapper for maven < 3.7.0

create a Groovy script distribution/executable via Maven

I have a project module full of groovy scripts which are run via embedded IntelliJ Groovy shell. In a new issue I need to have one of those scripts being run in combination with crontab. Needless to say I cannot just run groovy myScript.groovy dev to have this script executed out of the box - no the dependencies are missing for sure.
I now need a way to have this one particular groovy script being compiled and ready to run out of the box (with the use of the "dev" parameter)
Assuming that I put the myScript.groovy into a directory
main/
|_src/
|_groovy/
What do I need to have a maven build creating a usable executable for me to drop into my machine and let crontab run it accordingly.
I tried a lot of Maven Plugins - but never came far enough. Also I'm sure that there must be a way more trivial way to achieve this since it's a simple build operation in my opinion.

How to add java project dependency to play framework 2.2.1 java project

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.

How do you keep Hudson from giving Maven the -B option for builds?

When Hudson goes to build my project, it executes Maven as follows:
Executing Maven: -B -f /path/to/root/pom.xml clean install
This works fine on most projects. (The -B is for "batch" or "non-interactive mode", BTW).
But for this one project that uses AndroMDA (which I can't recommend for future projects, it's really a pain-in-the-butt; slows down the build by 1000% with code generation for things that could be trivially done with inheritance and annotation-based config).
For some reason unbeknown to me, when Maven is given the -B flag the generated classes are no put on the classpath causing compilation errors for references to the generated classes. I've tested building manually with -B and without it and the result is that it builds fine without -B (outside of Hudson) and it doesn't build with -B (again, outside of Hudson).
Using Hudson version 1.369 and an external Maven 2.2.1 install.
Any advice greatly appreciated!!!
P.S. Hudson is AWESOME!!!!
The simplest version would be to have a free style project, and call maven yourself.

Setting groovysh classpath from a pom

I have a java project (not using groovy) but I'd like to interactively play with my java classes within groovysh. Is there an easy way to use the pom from my project to set the classpath of groovysh?
Just for the record, I've found a way to do it which I consider much more elegant when the project uses the gmaven-plugin: run mvn groovy:shell and you're ready to issue commands with the same classpath available to groovysh as the one available to the project in question!
MOP might help:
Scripting Goodies
Other times, you just need need the
CLASSPATH so you can use it in a
manually crafted script your running.
Try this.
mop classpath org.apache.camel:camel-example-pojo-messaging
Update: The above command can be used to output the classpath of an existing maven artefact. For example:
$ ./mop classpath org.hibernate:hibernate-core:3.3.2.GA
Prints the following output:
/home/pascal/opt/mop/repository/org/hibernate/hibernate-core/3.3.2.GA/hibernate-core-3.3.2.GA.jar:/home/pascal/opt/mop/repository/antlr/antlr/2.7.6/antlr-2.7.6.jar:/home/pascal/opt/mop/repository/commons-collections/commons-collections/3.1/commons-collections-3.1.jar:/home/pascal/opt/mop/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/home/pascal/opt/mop/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar:/home/pascal/opt/mop/repository/javax/transaction/jta/1.1/jta-1.1.jar:/home/pascal/opt/mop/repository/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jar
That can be used somewhere else. As I said, it might help but I'm not 100% sure it will suit your needs (it seems the artifact needs to be deployed in a remote repo).
You can add them to classpath with -cp e.g.
groovysh -cp some.jar:another.jar

Categories