Create JRuby library jar for use in larger Java application - maven

What is the best way to create a JRuby JAR file that contains compiled JRuby code to be used in a larger Java application, especially with Maven. It seems that most of the use cases with JRuby are to build apps at the top of the stack and integrate legacy Java code. So most of the documentation and resources are around building WAR files and standalone JARs. Both warbler and rawr build standalone JARs.
We have to take a slightly different approach of putting JRuby right in the middle of the stack, so I want to build reusable JARs that can be uploaded to an internal Maven repo and use them as dependencies the same way I do with any Java code. There's not much documentation on how to do this and I've only come up with:
Write a Rake task to jrubyc compile the JRuby files and stuff them into a JAR file
Try something like buildr or gradle to do the packaging
Has anyone done this before? Any recommendations on which approach I should take or better approaches? Thank you.

Related

Maven in Eclipse?

I am a total beginner at maven, I have read about it online but I am still confused how it can be used. I have eclipse Oxygen version installed and when I open projects I can see maven project option is already there. I was even able to create a maven project using YouTube tutorial. But now then I saw popular plugin called m2eclipse but I am not able to comprehend why is it actually used; when my application ran without it.
I am learning maven to get started with spring boot but I am finding it really overwhelming where to begin with, and many of the tutorial sites state to download maven (But maven already comes along with eclipse?)
Please explain.
Apache Maven is a build tool - a tool for compiling the source code of a project into a program that you can run (for example a jar file, or a war file that can be deployed on a Java EE application server). Besides automating all the tasks for building a project, it also gives you a standard way to organize your project and to keep track of dependencies (libraries that your project needs).
Why do you need such a tool?
When you write a small program that consists of one, or maybe a few source files, it's easy enough to compile it by hand on the command line, by directly using the Java compiler javac that comes with the JDK.
But when your project becomes more complex, and you have hundreds or even thousands of source files in multiple modules, it becomes really hard to keep track of everything and cumbersome to compile the files using javac. If your program needs libraries, it becomes even more complex, because you have to make sure that all the libraries are on the classpath, and some libraries need other libraries, which also have to be on the classpath.
A tool such as Maven helps you to compile all the source files in the right order and to keep track of all the libraries. Maven can automatically download libraries from the web and add them to your project, and downloading everything and building the whole project can be done with one simple command such as mvn clean package.
Spring Boot is part of the Spring Framework, which is a huge framework with tons of useful functionality for developing projects in Java. A Spring Boot project typically needs dozens of libraries, and it would be very hard to use if you'd have to keep track of all those libraries by hand - so that's why it uses Maven to manage all of this for you.
A Maven project is configured using a file named pom.xml - in that file, you describe your project and you put a list of libraries that your project needs. When you build your project, Maven will read the pom.xml file and figure out automatically what source files need to be compiled, and what libraries need to be downloaded.
m2eclipse comes preinstalled in Eclipse (at least when selecting "Eclipse for Java developers" or "Eclipse for Java EE developer"), thats why you were able to use Maven by default.
Still you probably want a command line Maven, because that's most likely how it will eventually run on the CI server, sometimes Eclipse Maven installation can produce different result than the command line install.

How to migrate build with xml-maven-plugin transformation to sbt?

Context: I'm trying to convert an existing scala project that's been built using maven to SBT so I can take advantage of the multiple scala version building logic that SBT brings to publish 2.10 and 2.11 artifacts for this library.
Problem I'm running into is replicating the xml-maven-plugin transformation configuration (I used a gist, because it didn't paste into here very nicely at all, and it's not small)
Is my solution to re-implement whatever the xml-maven-plugin is doing in scala code in a Build.scala (or other file) and use it in build.sbt as a task? Is there an existing plugin out there for SBT that can do XSL transformations? Is there a much simpler way to do this?
You may be able to stick with the maven plugin using sbt maven plugin. It may or may not mess with your build, but may be worth a try at least.
For pure scala, you have something like sbt-xslt-plugin. It's very immature and outdated. However, you may be able to quickly modify it to do the tasks you were using xml-maven-plugin for. The amount of scala code that makes up that plugin is about as much xml code you have in your xml-maven-plugin config, so it should be a heavy task.

Incorporate large number of 3rd party jars into maven

I'm working on a project that has a reliance on a significant number of 3rd party jars; these jars contain both proprietary classes and custom/patched versions of existing libraries. I'm trying to figure out how to tie these jars into the maven architecture so as to be CI friendly.
My initial idea was to create an uberjar of all these libraries, and add that one uberjar to the maven repository, however I have not been able to figure out how to take this set of standalone jar files (that are not dependencies) to merge like that. There exists lots of documentation on how to uberjar a project and its dependencies, but not standalone jars.
I feel like i'm missing something basic, or maybe there is a better way. Any recommendations are welcome.
You would be better off to proceed as follows:
Set up a repository manager.
Write a shell script that runs mvn deploy:deploy-file for each of your jars, generating the GAV with a simple algorithm.
treat them like anything else.
To elaborate on Step 2:
G:A:V - my-company-name:name-of-jar:version-based-on-todays-date.

JBoss Modules for large number of jar dependencies HOW TO

I'm trying to figure out how to make my WARs lighter by putting JasperReports, Apache POI and other heavy libs directly to JBoss AS by using JBoss Modules.
Now, Jasper uses many many libraries to generate PDF or XLS files as you can see here. Our templates are pretty old and we are stuck with old jasper version 3.7.1 which of course uses older versions of libraries such as commons which are already present on JBoss AS 7.1.1 modules.
How can I make one "big" module which will contain all jars used by Jasper and keep other parts of application using newer modules?
Putting all jars into separate directories seems so much work without guaranteed success, can we put everything into one module without creating package alike directories?
We started with JBoss modules recently and wrote a small plugin for Maven that generates module folders with module.xmls based on XML descriptors. The plugin is called smartics-jboss-modules-maven-plugin and you'll find additional information about it at the project's blog.
We just started to work with it, but it already makes the process of synchronization between the POM and the module.xml (plus directory structure) for our projects very easy.
The downside of this approach is that you have to learn an additional XML descriptor and have to configure an additional Maven plugin.
If you want to give it a try, the plugin is licensed under Apache License 2.0.
The creation of JBoss modules for external libraries can be automated through maven as explained in another answer here on SO. The author has posted a GitHub project too. This can lessen the pain in managing lots of transitive dependencies.

What can I leave out when creating an executable JRuby jar?

I've attached an image of what JRuby.jar contains:
http://www.freeimagehosting.net/uploads/fbfd966375.png
The problem is that even for simple scripts, the resulting jars have about 8mb. Can you tell me which folders I could remove from there, and still have it running ... or what's the purpose of some of that folders?
You could try repackaging the jar with pack200 if you just want a better compression ratio.
JRuby does bundle all its dependent Java libraries, so it won't be easy to trim those back. Stay tuned or follow progress on JRuby for Android for a more minimal jar.

Resources