Setting groovysh classpath from a pom - java

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

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.

Is it possible to use javac just to check correctness and not produce any output?

Can I run javac (or another tool, if javac can't be used as such) just to check for correctness of a project: if there are syntax errors or missing imports, incorrect use of annotations, access violations, en somme, anything that would be reported by eclipse when you choose the action build.
You can run javac with two options :
-c to give the path of you files,
-s for path to libraries
If you really want to check the project at it is, I would recommand to use a dependency manager like Maven or Ant which can check errors, compile, packages, etc..., but it will need some configuration in your project using a configuration file (a pom.xml for Maven)
The fact that javac runs properly does not prevent you from getting NoClassDefFoundError problems due to missing dependencies.
The equivalent of an Eclipse build just without producing class files is invoking the JDT batch compiler with option -d none (see here for available versions).

View exact java commands issued by SBT

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.

Setting custom Class Path while executing mvn exec:java

I have a simple use case of running a main method from a jar . This jar get created as a part of mvn packge and gets stored in myproject/target/myproject-jar-withdependencies
How i am running it right now is using a simple java -cp {path-to -jar} {mainclass} . I am trying to use mvn exec plugin for this but am having problems running it
The crux is that i need to force maven to find the main class inside a jar that is in target/
directory . I tried using -cp and jar using the argument tag but unfortunately that doesnt work either . Maven doesnt seem to recognize the jars inside the target directory as belonging to the class path
I need to specify the custom classpath in the exec plugin (the docs in mvn exec dont give much information to this)
Any pointers is much appreciated
Answered in comments:
Sorry about the very late update. But this is fixed. My pom was
misconfigured – Nitin Feb 8 '13 at 23:47

Categories