How do I create an uber jar in Ceylon - packaging

I have a Ceylon project. I would like to distribute it in an uber jar that includes all dependencies, so that it can be executed with simple
java -jar myproject.jar
Is this possible in Ceylon?

The upcoming Ceylon 1.2.3 has the fat-jar subcommand. See https://github.com/ceylon/ceylon/issues/5932 which tracks this feature. To use it now, you need to download a nightly build from http://ceylon-lang.org/download/ or build Ceylon yourself.
With Ceylon 1.2.3, assuming your module is called myproject, you can do
ceylon-1.2.3/bin/ceylon fat-jar myproject
java -jar myproject-1.0.0.jar
This executes code in function run() in file source/myproject/run.ceylon.
The uberjar for a simple hello world program has currently 2.4 MiB.

The Ceylon Gradle Plugin can do it for you, just use the createJavaRuntime task:
gradle createJava
Run the application with:
bash build/java-runtime/run.sh
or the equivalent in your OS.
If you copy the java-runtime directory to a machine that has no Ceylon installed, only the JVM, it will work.
It's not a fat jar, but you can distribute this as a zip and get most of the same benefits.

Related

Dependency on package in git without jar file

I am distributing a Java package via git for other people to use. I am currently supplying a jar file to go with the source. This way, the user only needs to clone the project once into Intellij IDEA. Projects using the package can then follow this procedure
Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
to use the package.
This works, but distributing a jar does not feel nice security-wise. On the other hand, this discussion
IntelliJ IDEA - adding .java file to project dependencies
suggests that to use the source code, you need to copy it into your src folder.
Is there a way to distribute source code (java files) only so that if multiple projects use the same package
the package only needs to be downloaded once
the package can be kept up to date with git pull?
I would really recommend not include jar or any binaries in a Git repo and the best approach to keep these dependencies in a local Nexus repository and use maven or Gradle as your dependency management tool.
I found a working solution:
Supply an Ant build file with the package. The build file compiles classes and packages them into a jar file. The default target is building the jar, which depends on compiling the classes.
Provide users with instructions on how to set the given Ant build file as a build file in Intellij IDEA and build the default target.
Then instruct them to follow the steps in the first link above to add the jar as a dependency.

IntelliJ IDEA export Runnable program as Uber Jar

In Intellij IDEA, If a Java or Groovy class has "main" method, Intellij provides an option to Run the program and it figures out the classpath based on the classpath of the module. Run <className>.main() works fine. However I want to export a Uber jar for the corresponding including all the required jars from the classpath so that I can run this program somewhere else. I did not see an option in Intellij to export the java/class as uber(fat) jar. I am not looking for a gradle/maven build script to create the jar. Checking if Intellij has an option to do this automatically.
Using Intellij Ultimate Edition 14.0.4
I think that this feature is what you are looking for:
https://blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/
The key step is to customize the artifact and select "select to target JAR".

How to package an Apache module with Maven

I have a apache_mod.c which is supposed to be updated for continuous integration
I would like to use Maven to compile this module for generating apache_mod.so
Then packaging it in .jar
I can't find how to compile the apache_mod.c with Maven to get apache_mod.so because it seems that an Apache2 module needs to be compiled with apxs2 command which already put the *.so file in /usr/lib/apache2/modules.
So, do you have any idea how to compile apache_mod.c with Maven in order to get apache_mod.so to package it?
I don't think that putting *.so (shared object) into jar archive is correct solution, but to answer your question how to compile native c or c++ files using maven, you can use the native plugin http://mojo.codehaus.org/maven-native/native-maven-plugin/. Also, the apxs2 is just wrapper around gcc, so you don't have to use apxs2 to build apache module. You can just use gcc.
Seems I tried to do two things in one.
Generating *.so and packaging it are two different things.
So here is the process :
Having a Maven project compiling and generating *.so
Having a Maven Assembly to package *.so and others files and *.war
Seems Boris has been definitly right. Using Maven native plugin allow to compile *.c in *.so then Maven assembly plugin is used to package it.
Thanks for all.

Packaging a Jython program in an executable jar

I am trying to package a jython program into an executable jar which the user can simply double-click to run without installing jython ahead of time. Ultimately, I would like to include an additional library which I wrote with the jar, but at the moment I am just trying to package a simple program and have it run from the jar.
I have tried following the jar instructions in the "Using the Jar Method" section here: Jython FAQ: Using the Jar Method
I have also looked at slides 25-28 here: Jython Update 2012 slides
And finally here:
stackoverflow Question: Distributing My Python Scripts as Jars with Jython
I have installed jython 2.5.3, jvm 1.6, and python 2.7.3 on my mac which is running OS X 10.8.3.
These are the steps I go through to create the jar and run it:
Create a copy of jython.jar from my jython installation directory.
zip -r jython_copy.jar Lib (where Lib is the folder in the jython installation directory)
cp myJythonProgram.py __run__.py (myJythonProgram.py does not include an 'if name == main' line)
zip jython_copy.jar __run__.py
export CLASSPATH=/path/to/my/app/jython_copy.jar:$CLASSPATH
I have tried running the jar using all three of these methods:
java org.python.util.jython -jar myapp.jar
java -cp myapp.jar org.python.util.jython -jar myapp.jar
java -jar myapp.jar -jar myapp.jar
This works if my program doesn't use any import statements.
However I am running into an issue where some python packages are not able to be found when I run the jar. For instance, I get the error "ImportError: No module named random" when I include the line from random import random in my program. No errors occur on lines in the program when I import from javax.swing, java.awt, time, or math.
Additionally, I tried to package a jar with my library and a jython program which imports my library using the previous steps as well as the following additional steps:
zip jython_copy.jar myLibrary.jar
jar ufm jython_copy.jar othermanifest.mf
othermanifest.mf only contains the line Class-Path: ./myLibrary.jar.
This too gives the error "ImportError: No module named myLibrary"
I would appreciate any insight into what I am doing incorrectly or other steps I should take.
Thanks!
I realized what the problem was and I wanted to document it in case anyone else has the same problems.
I was using the jython.jar file that came in the standard installation of Jython, and NOT the standalone jython.jar (the instructions at Using the Jar Method mentions this, but the instructions at Building Jars do not). I am still unsure why copying the Lib/ folder of the standard installation into the jython.jar that came with that installation didn't work on my system. However, once I used the standalone jar, things started to work more smoothly.
Additionally, I was able to get my library to work with the packaged file by doing three things in addition to the steps I laid out in my question:
Exploding the standalone jython.jar and copying the folder with all of my library files into Lib, then create a new jar. This seemed to be the easiest way to include my library and allows me to package everything into a single jar.
I discovered after reading Frank Wierzbicki's answer in Why does Jython refuse to find my Java package? that because I am now using the standalone jar, I could no longer use imports of the style from java.awt import *, instead I needed to fully specify each thing I was importing, for example from java.awt.Font import PLAIN, BOLD, ITALIC. So I went through the library's imports and fixed the few that were of the wrong style.
Now that I am adding my Library directly to the Jar's Lib folder, instead of writing Class-Path: ./myLibrary.jar in othermanifest.mf, I put Main-Class: org.python.util.JarRunner as per Frank Wierzbicki's answer in the post I mentioned in my question: Distributing my Python scripts as JAR files with Jython?
This allowed me to create a double-clickable executable jar containing my library and jython file that I wanted to run.
There are two solutions. They both work, but one better than the other.
I believe you can rename your python script as __run__.py, place that file inside the .jar file, and pass the .jar file through a python interpreter. See https://wiki.python.org/jython/UserGuide#invoking-the-jython-interpreter for more.
Multiple methods to run Jython from the java code while running through JVM are described here, at the Jython documentation.
EDIT:
You can execute a command line code that runs the python file you want.
Link to an example of running command line code from java here.

Play framework and IntelliJ new project creation -- errors

I am looking at Play 2.0 for the first time. I installed it using homebrew
~/code $ brew info play
play: stable 2.1.0, HEAD
http://www.playframework.org/
/usr/local/Cellar/play/2.1.0 (3998 files, 254M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/play.rb
I create a new project and set it up for IntelliJ (12.0.4)
~/code $ play new playtime
...
play! 2.1.0 (using Java 1.7.0_15 and Scala 2.10.0), http://www.playframework.org
...
OK, application playtime is created.
...
~/code $ cd playtime/
~/code/playtime $ play idea
...
...
[info] Created /.../playtime/.idea_modules/playtime.iml
[info] Created /.../playtime/.idea_modules/playtime-build.iml
~/code/playtime $
I open IntelliJ and rebuild the project. I get
scala: Output path /.../playtime/project/target/scala_2.9.2 is shared between: Module 'playtime-build' production, Module 'playtime-build' tests
Currently external Scala compiler prohibits output path sharing.
Either disable the external build mode or configure separate output paths.
TIP: you can use Project Artifacts to combine compiled classes.
How to make a clean empty project that builds ?
Why does Play create a -build module ? What is it used for?
Why does this module reference a Scala 2.9.2 path ?
Libraries scala-2.9.2 and scala-2.10.0 also created, but not used. Why?
1) How to make a clean empty project that builds ?
Play 2.0 plugin for IDEA 12.1 (version 0.2.25 or 0.2.26) will be uploaded soon will be much better in this direction, I hope you will not have problems with compilation here.
2-3) Why does Play create a -build module ? What is it used for?
Build module is created for SBT build file. SBT depends on Scala 2.9.2 (that's why this module requires Scala 2.9.2), so to have better editor for such build file, SBT IDEA plugin creates this module (this is third-party plugin, our own SBT plugin will be implemented soon). However this is not right to create such confusing module, in Play 2.0 plugin 0.2.25 project creation will clean this module. So you will not have this confusing module.
4) scala-2.10.0 library is used in Scala facet for Scala compiler. However Scala compiler is not used in Play 2.0 project, we are using play compiler in our support (with bundled with play SBT compiler), so in general it's not used, but you still have this library, otherwise you will get some error messages from Scala compiler, what is Scala plugin usability problem, you can post new issue about it here: http://youtrack.jetbrains.com/issues/SCL