Compiling Java sources with Clojure deps.edn - java

How do I configure my Clojure CLI deps.edn file to compile Java source files along with my .clj Clojure source files?
I found badigeon which can compile Java sources, but I'm struggling to use in my simple project.

You can now do that with clojure.tools.build

Without knowing more about your context ...
The "best" way to do this currently, is to separate your Java and Clojure sources into two projects. In the Java project, create a jar with the compiled classes (using standard Java tools - perhaps make and javac) and install the jar into your local maven repo. Then add the jar file as a dependency in the deps.edn of your Clojure project.
You might also be able to use the jar directly, without installing locally, by using the local/root feature in deps.edn. See the Deps Rationale for how to do that.
Another way would be to arrange to have the Java sources compiled into a classes sub-directory of your combined (Java / Clojure) project and then add the classes directory to the :paths key in your deps.edn. The creation of the class files will (again) have to be done with Java tools or shell scripts - outside of clj.
There are some recent developments in clj that may make this easier in the future.

clj will not do that.
lein do a lot of things that are out-of-scope for clj command line.
You may find some library that do that, then you can call clj -m lib-that-compiles-java

Related

Run groovy uncompiled script with single jar file on java jre

I would like to execute uncompiled groovy scripts with the java jre. I would like to provide just one jar file to do this. I think in older groovy versions this was possible with a groovy-all jar.
e.g. java -cp lib/groovy-all-2.4.6.jar;. groovy.ui.Main myscript.groovy
But this groovy all jar does not exist for new groovy versions. Is there another jar to do that?
I found the gradle-groovy-all project in this thread. This works fine for me. With the newest commit on the master branch the dependency org.apache.ivy is incuded in the built jar.
There are many groovy-$something artifacts (sql, json, ...) and
all was just the combined jar with all of them in it in the 2.4 days.
Now the "-all" is only deployed as Bill Of Materials, that itself no longer
is/contains a jar, but points to all other groovy-$something artifacts itself as transitive deps.
So using "groovy.jar" and "groovy-(a|b|c).jar" might be a way out for you and this all boils down to one jar, if you don't need anything else but groovy.jar.
Or you could roll your own "all" jar (e.g. build a uber-/fat/shadow-jar
in a project with all deps you need (e.g. groovy-all and whatnot).

Gradle: Create a non-executable jar and executable shell script with dependent libraries as a package distribution

I am not a big fan of creating fat executable jars for java programs as it involves a massive overhead when I have multiple executable programs from the same project.
I want to be able to create a single library-like jar and create corresponding .sh scripts which pretty much have the structure of:
java -cp classpath_libs main_class program_args...
or any other executable where I can customize it to my needs but in a similar fashion(ex: hadoop jar project_jar main_class classpath_libs program_args). Is this achievable in gradle? if so, how? Note, I need to create multiple scripts using different main classes from a single project.
Key requirement here is to be able to use final fully resolved classpath string.
UPDATE: I have seen examples of using the application plugin but it creates an executable jar with dependent libraries packaged into it. This is NOT what I am looking for.
So far as I have found, it appears there's no plugin that handles this directly. So, I used the java-library plugin, used the configurations.runtime classpath value and created the necessary scripts and the copy task to copy the libraries necessary into the necessary directories. For anyone interested, you may also try the distZip option in application plugin where gradle does create scripts for execution and package the necessary libraries in a distribution. You can take a look at the output of the script to see how the classpath is structured and create something similar.

How to build ceylon using the ceylon commandline tools?

How can I setup and build the ceylon distribution as a mixed java and ceylon project using only the ceylon commandline tools instead of ant?
I assume having cloned the git repository, cleaned and dist-ed the ant project following the instructions in https://github.com/ceylon/ceylon, ceylon/dist/README.md, and therefore - among all the other parts - having ready a parser from the grammar using antlr.
Cant you outline the necessary steps, or show a script that collects the required .java and .ceylon files and the resources and .xml files and so on from the git / ant project. Cant you setup one on git hub?
Specificly, what dependencies am I to put where (repo), and how must I handle version strings like ¨1.2.1¨ when working with java dependencies (jars, not cars) in the ceylon project?
For the sake of simplicity I could do with building only the compiler-java and related subprojects, specificly the typechecker, leaving away the compiler-js and its related .js files.
Finally, why is the ceylon distribution built with ant instead of the ceylon tools?
I can only partially answer my own question as far as the the build of the ceylon typechecker is concerned. After generating all the necessary java source files and consolidating the source directories the typechecker was built without errors and could be used without runtime errors.
Speaking for myself this is enough to discard the hypothesis that compiling a java project is an enterprise that never leads to success. In this considerable instance it even led to success at runtime. This is truly amazing.

How can I compile Scala code without using scalac

Let's suppose I have a file called Main.scala that I want to compile and run.
In a normal environment I can just do scala Main which automatically performs compilation and runs the file.
Now I am trying to deploy scala source code to another Server, on which I am not allowed to install scala. It is just possible to copy files (such as scala-library.jar and scala-compiler.jar) and Java 1.6 is pre-installed.
It would of course be possible to compile to bytecode locally using scalac Main.scala and execute the resulting .class-files using java -cp [...] Main.
For my workflow it would, however, be better if I could just checkout and compile the scala sources on the remote server directly.
Is there any possiblity to realize this compilation task with the tools available or by copying additional binary/jar files?
I would strongly suggest that you use a build tool. Many open source projects use sbt (http://www.scala-sbt.org/). You can use an sbt plugin (https://github.com/sbt/sbt-assembly) to create a fat jar with all your dependencies.
You can also use Maven and Gradle.

Compiling without having to put project files under classpath

I want someone to be able to compile the code without then having to set the CLASSPATH to the project directory. Is this possible?
You can set the classpath to be used for the compilation as a parameter passed to the compiler instead of setting an environment variable. The parameter is -classpath or -cp.
The classpath needs to be set somehow, though using the environment variable is not recommended these days. Typically, projects that people are supposed to compile for themselves are distributed with either an Apache Ant build script or a Maven POM descriptor. Both of these build automation systems can do much more than just compilation, but both require some time to learn if you haven't used them before. However, it is time well spent, as they can save you a lot of time on all kinds of repetitive tasks, and both are very commonly used in Java projects.
Use a build tool, like Ant or Maven. They use a project descriptor of one sort or another to manage the classpath for you.
Sounds like you want to create a .jar
The jar tool in the JDK puts your .class files in an archive. Then you can just reference the archive on the classpath or with the -jar flag for the java executable.
If you create a manifest for the jar, you can make the .jar runnable with a click from Windows and most other desktop environments.

Categories