software:java:java

This is an old revision of the document!


Projects in Java

Below is a basic Java example and steps you can follow and apply to your filename.java. Remember Unix is case sensitive so it is very important for the filename HelloWorld.java match the class name defined in the file as HelloWorld.

HelloWorld.java
public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("Hello, World!");
  }
}
All compiling for Java must be done on a compute node which means you must set your workgroup followed by qlogin to work on a compute node. Remember to use VALET to select the appropriate version of Java.

On Farber and Mills, check the versions of java development by using

$ vpkg_versions openjdk

and select the appropriate version to compile and create the HelloWorld.class file. The following example is based on the user traine in workgroup it_css on Farber using commands to create a directory /home/work/it_css/traine/java to store all the files associated with this example, 'qlogin' to a compute node, load openjdk verison 1.8.0 using VALET, compile and test HellowWorld, and lastly exit the compute node and return to the head node.

 
[farber ~]$ workgroup -g it_css
[(it_css:traine)@farber ~]$ cd /home/work/it_css/traine/java
[(it_css:traine)@farber java]$ cat HelloWorld.java
public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("Hello, World!");
  }
}
[(it_css:traine)@farber java]$ qlogin
Your job 1392265 ("QLOGIN") has been submitted
waiting for interactive job to be scheduled ...
Your interactive job 1392265 has been successfully scheduled.
Establishing /opt/shared/univa/local/qlogin_ssh session to host n040 ...
[(it_css:traine)@n040 java]$ vpkg_devrequire openjdk/1.8.0
Adding package `openjdk/1.8.0` to your environment
[(it_css:traine)@n040 java]$ javac HelloWorld.java
[(it_css:traine)@n040 java]$ ls
HelloWorld.class  HelloWorld.java
[(it_css:traine)@n040 java]$ java HelloWorld
Hello, World!
[(it_css:traine)@n040 java]$ exit
[(it_css:traine)@farber java]$ 

Back on the head node, you need a submission script to run your java job. For this simple example, we will use a copy of serial.qs from /opt/templates/gridengine on Farber and call it submit.qs, and modify it to run our HelloWorld executable.

submit.qs
#
# Template:  Basic Serial Job
# 
# Change the following to #$ and set the amount of memory you need
# per-slot if you're getting out-of-memory errors using the
# default:
# -l m_mem_free=2G
#
# If you want an email message to be sent to you when your job ultimately
# finishes, edit the -M line to have your email address and change the
# next two lines to start with #$ instead of just #
# -m eas
# -M my_address@mail.server.com
#
 
# Add vpkg_require commands after this line:
vpkg_require openjdk/1.8.0
 
# Now append all of your shell commands necessary to run your program
# after this line:
java HelloWorld

Now we can run our job using qsub submit.qs on the head node. The example below shows as well as commands to monitor the status of job and view results of the job run.

(it_css:traine)@farber java]$ qsub submit.qs
Your job 1392329 ("submit.qs") has been submitted
[(it_css:traine)@farber java]$ qstat
job-ID     prior   name       user         state submit/start at     queue                          jclass                         slots ja-task-ID
------------------------------------------------------------------------------------------------------------------------------------------------
   1392329 0.00000 submit.qs  traine        qw    12/04/2017 16:54:28                                                                   1
[(it_css:traine)@farber java]$ ls
HelloWorld.class  HelloWorld.java  submit.qs  submit.qs.o1392329
[(it_css:traine)@farber java]$ qstat
[(it_css:traine)@farber java]$ cat submit.qs.o1392329

[CGROUPS] UD Grid Engine cgroup setup commencing
[CGROUPS] Setting 1073741824 bytes (vmem none bytes) on n038 (master)
[CGROUPS]   with 1 core =
[CGROUPS] done.

Adding package `openjdk/1.8.0` to your environment
Hello, World!
[(it_css:traine)@farber java]$

Please review the templates for job submission scripts in /opt/templates/gridengine on Farber and Mills. If you do not specify any resources, by default you will get 1 core and 1GB of memory (a simple serial job) on Farber.

  • software/java/java.1515167350.txt.gz
  • Last modified: 2018-01-05 10:49
  • by anita