How to build ceylon using the ceylon commandline tools? - java

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.

Related

what is the equivalent project file for a Java project?

What is the equivalent project file for a Java project? For example, a C# project file is denoted by the delimiter of .csproj. So what would it be for a Java project? Is it dependent on what IDE I am using for Java?
I did some search online about this and it seems to me that the answer to this question is dependent on the IDE. From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated. I do not want to be steered in the wrong direction on this and so I want to first ask around for guidance.
You're probably looking for the build file, not the IDE project definition.
Is it dependent on what IDE I am using for Java?
Yes. IntelliJ has .iml files, and Eclipse has .project (that's not a file ending - that's the file), as well as .classpath, .factorypath, and more. But, many of these are effectively generated or just refer to the build file. In C that tends to be called Makefile, in the Java ecosystem, Gradle and Maven are the 2 most popular build tools; they have build.gradle and pom.xml respectively. These would be more useful as basis for knowing how a project is 'put together', so to speak.
From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated.
That's very basic and should rarely work except for the simplest projects. For example, most Java projects have source files, test files (also source files but they are not part of the distribution), and resource files (non-Java files that are also needed for the app; think about the images for the icon on a button), as well as a ton of dependencies (third party libraries used by the Java app).
Given that folks like many IDEs, the IDE 'config file' is not what you are looking for, and many projects don't even check these into source control (and probably shouldn't). Together with the source, you have a build file. This build file knows how to download dependencies, compile every artifact (there doesn't have to be one; maybe there's the test code to the built, the main app, a plugin for some other tool, and an installer. Build tools can handle all that), run the tests and report on them, possibly even tell you about code coverage, and they usually can run the app, but more generally, you just want to tell the build tool to build a distributable for each relevant artifact.
Those build files are what you're looking for. With those you can build your project, or point an IDE at them and then you can edit the project with all the dependencies and classpath linkages all worked out for you.

Is it possible to move class files created to the code locations in gradle?

I am quite new to gradle, currently working on a java project where I have to migrate from ANT to Gradle. The ANT scripts compile and create .class files at the java code location itself. While In Gradle it stores all output class files in build/classes directory. Is it possible to create class files at the code location in Gradle? I was thinking that would make the migration a bit easy for me to follow. If it is not possible, is there a reason why Gradle uses separate output folder? Thanks.
You can certainly configure Gradle to however you like. For example, to change the output of the compileJava task, you would change destinationDirectory property.
Gradle has a dedicated guide on migrating from ANT to Gradle: Migrating Builds From Apache Ant
is there a reason why Gradle uses separate output folder?
Well, it is a different build tool, but mainly because it is by convention. Both Maven and Gradle follow this convention and it is well established.

How do I add a Maven dependency in VS Code for a simple Java project (i.e. an unmanaged folder without any build tools)?

I'm trying to build an AI model for the Mario-AI-Framework using the Deep Java Library (DJL). I'm using VS Code with the Java extension, as this is part of a larger project, mainly in Python. Now I have a Pytorch model trained and ready to go but I need the DJL Pytorch engine to load it in Java. The problem is, the only info I can find on how to import this thing uses Maven or they build it from source using Gradle. I'm not used to working with Java projects and importing libraries so I'm at a complete lost here. If anyone could point me in the right direction I would appreciate it.
You can always download the jar files stored in the Maven repository and put them manually on your classpath.
Remember to do so recursively for all artifacts referred to until you have all the jar files that Maven would have downloaded for you.
For instance if you need commons lang you can get 2.1 from https://search.maven.org/artifact/org.mod4j.org.apache.commons/lang/2.1.0/jar - note the Downloads link in the upper right.
You might find it easier to rework what you have into being a Maven project, so your tooling does it for you.

Compiling Java sources with Clojure deps.edn

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

How do I check installed JARs, external libraries, etc. on three different Java IDEs?

I've written programs in several languages and have tutored students in computer science, but just starting to learn Java on my MacBook. Regarding this question, I'd be happy with any answer that points me to available information or tutorials that address my question; I'm capable of understanding advanced things.
I've been searching for the right IDE for me as well as something I can use with my students, and I've tried IntelliJ, Eclipse, and VS Code. Along the way I've installed external JARs to provide extra capabilities, such as Apache Commons.
Things are getting confusing. I've lost track of how I got to the present state in each IDE. I'd like to understand better how to know the overall Java environment that any given project is using on each of these IDEs, including any external JARs and where they are located. And I'd like to know if they borrow from the Java system environment.
My goal is to understand how my own system got to the way its currently configured, to update my configuration on a project-by-project basis, and to help my students get a matching configuration.
I'd also like advice on the right way, or simplest/cleanest way, to install external JARs.
Maven
Question: I'd also like advice on the right way, or simplest/cleanest way, to install external JARs.
If you really wanna work in a organised way and wanna focus completely on coding rather than looking for dependencies to work with , then try building your projects with Apache Maven. The magic wand of Maven projects are pom.xml file where all magic happens depending upon your wish.
Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software:
Describes and manages how software is built.
Describes and manages dependencies (various libraries used by your code).
Why Maven:
De facto standard
Able to compile, test, pack and distribute source code ( different Goals)
Robust dependency management (Most important from my point of view)
Extensible via plugin
Good community support and many fan boys around.
The big 3 IDEs (IntelliJ, NetBeans, and Eclipse) all having good
support for Maven, letting you use Maven as a substitute for their
own proprietary project definition and build process.
Maven famously caches all of its dependencies in the ~/.m2
directory, which is sometimes called the local Maven repository.
Maven local repository keeps your project's all dependencies (library jars,
plugin jars etc.). When you run a Maven build, then Maven automatically
downloads all the dependency jars into the local repository. It helps to
avoid references to dependencies stored on remote machine every time a
project is build.
You can simply deploy your project as JAR, WAR, or EAR file and use it on different IDEs or as standalone.
All IDEs need a way to know your project's dependencies. You can either tell them that yourself or let a build tool do that.
Manual dependency handling: by adding the jars to your project. This is probably the fastest way when working on a small project, with one developer, on a specific IDE, with few dependencies. Usually when telling the IDE that this .jar is a dependency of your project, the IDE stores that reference to a project-specific file (eg. in Eclipse the .classpath file which you can edit with a txt editor and see the dependencies yourself). However, it kind of locks your application to your IDE. Most IDEs have cross-IDE support for import and migration, but using both IDEs at the same time can be confusing when a dependency is added to one and has to be repetitively added to other as well. Furthermore, your dependencies have dependencies on their own. By adding manually your jars you are responsible to find and download their own dependencies as well.
Use a build tool: There are 3 standard such tools right now: Apache Ant with Ivy, Apache Maven and Gradle. All of them have support in the major IDEs for Java: IntelliJ IDEA, Eclipse and NetBeans. All of them use some extra build-tool specific files to store your project's configuration and subsequently configure your IDE and the IDE-specific files. That way, your project becomes IDE-agnostic, the IDE outsources the dependency handling to the build tool. These tools will download any direct or transitive dependencies of your project in a local directory or you can compile jars in a specified folder. From those, Ant is the oldest (with Ivy adding dependency handling support), Maven was developed after that and Gradle is the newest and probably the most flexible. In production however Maven is by far the most established one right now.
It would be also useful to look up the Standard Directory Layout. If you adhere to that, it will be easier to work/start with either Maven or Gradle.
Finally, you can search and find most of the free libraries in Maven-Central where conveniently their Ivy/Maven/Gradle script is added as well for you to use on your build-tool script. In many cases a .jar is provided as well if you prefer to manually add it as a dependency.
Regarding VS Code, I think it supports these tools through plugins but I'm not sure.

Categories