classpath

Setting the classpath in a Scala script (Scala shell script)

Scala script FAQ: How do I set the CLASSPATH in a Scala shell script?

If you need to set the CLASSPATH when executing a Scala script, the following example code at the top of your script should do the trick for you:

#!/bin/sh
exec scala -classpath "lib/htmlcleaner-2.2.jar:lib/scalaemail_2.9.1-1.0.jar:lib/stockutils_2.9.1-1.0.jar" "$0" "$@"
!#

As you can see from that code, I'm adding three jar files to my classpath at the beginning of my Scala shell script.

How to add a new jar file to the Scala REPL classpath (interactive command line)

Scala REPL FAQ: How do I add a Jar file to the Scala REPL classpath? (The Scala REPL is the interactive command line you get if you just type "scala" at your command line.)

To add a new jar file to the Scala REPL classpath (interactive command line classpath), use the ":cp" command at the command line, like this:

scala> :cp myjar.jar

After you do this, you should see a reply from the REPL like this:

How to compile a Java program with Ant

While I'm digging around through Ant build scripts today, here's a sample Ant target I created that demonstrates how to compile a Java program, while also showing a few other things, including how to exclude your JUnit tests during the compile process.

Ant compiling - How to reference the jar files in your lib directory during your Ant compile process

Here's a quick snippet of code from an Ant build script that demonstrates how to create a classpath variable in an Ant script, where the classpath is built from all of the jar files in your project's lib folder:

How to turn a list of jar files into an Ant classpath string

Summary: Using a list of jar files to create a dynamic classpath to write to a manifest file in an Ant build script.

In this tutorial I'd like to demonstrate how to convert a list of jar files in a standard lib directory into a classpath string you can use to define a manifest file in an Ant build script. By converting this list of jar files into a classpath string, the build process for your jar file can depend on any number of external jar files, and you can create this classpath dynamically.

Java - Build an executable jar file by referencing your dependencies

Summary: How to build an executable jar file that has dependencies on other jar files.

If you ever need to create an executable jar file that has dependencies on other jar files, this tutorial is for you. I'll show you ever thing you need to do -- including the use of an Ant build script -- so your users can just type something like this at the command line:

java -jar my-application.jar

to run your Java application.

Ant classpath - How to build a classpath variable in an Ant script

Summary: An Ant classpath example.

Here's a quick example showing how I typically build a variable to represent my classpath in an Ant build script.

Where is Perl looking for modules to include?

I started working on a new Unix system yesterday -- an HP-UX system I've never worked on before -- and I quickly realized that I needed some Perl modules installed. While working with another person the question quickly came up, "How do you know where Perl is looking for currently installed modules?"

Ant tip: How to dynamically add all your jar files to your classpath

Here's some sample code you can use in your Ant build scripts to add all the jar files in a directory tree (typically your lib directory) to define a classpath for your Ant build/compile task:

DOS batch files to compile and run a Java program (and create a jar file)

This isn't the most high-tech way to do things, but I thought I'd share these Windows (DOS) shell scripts that I'm currently using to compile a Java application, create a Jar file to distribute the application, and finally run the application. I ended up creating these scripts because of configuration problems on my Windows PC, but I thought they might be useful samples for others.

Syndicate content