Your java it out of date

Dialog “Your Java version is out of date”

Problem

Your java it out of date
Your Java version is out of date
  • If you start a Java application on Windows this dialog shows up
  • Especially on servers this can be annoying, because it prevents the start of the application
  • You want to get rid of this dialog
  • (But you should update Java periodically)

Solution

1. Create the following path:

C:\Windows\Sun\Java\Deployment

2. Create in this path a file named Deployment.config

3. Paste the following content

deployment.system.config=file\:C\:/Windows/Sun/Java/Deployment/deployment.properties
deployment.system.config.mandatory=true

deployment.system.config.mandatory forces java to load the property file set in deployment.system.config.

4. Create the file deployment.properties

5. Paste the following content

deployment.javaws.autodownload=never
deployment.javaws.autodownload.locked
deployment.expiration.check.enabled=false
deployment.expiration.check.enabled.locked
deployment.expiration.decision=never
deployment.expiration.decision.locked
deployment.expiration.decision.suppression=true
deployment.expiration.decision.suppression.locked

You will find description of the parameter here.

deployment.expiration.check.enabled is set to “false” to suppress the prompt. deployment.expiration.check.enabled.locked will lock the value, so a non root user cannot change it.

Optional:

  • deployment.javaws.autodownload – Prevent autodownloadin in java web start
  • deployment.expiration.decision – Remember the decision and suppress them

Fin

Advertisements

Polarion – Create Work Item with Wiki page

Problem

  • You want to create a polarion work item with a wiki page

Solution

First, if you have no wiki page, create one.

In Polarion you have to create a work item stub in the first step. Subsequent, fill the needed fields and finally save the object.

## Get project id
#set($projectId = $doc.getProject($doc.getSpace()))
## Get project object
#set(pro = $projectService.getProject($tprojectId))
## get trackerproject to create stub
#set($tpro = $trackerService.getTrackerProject($pro))

## Open transaction
$transactionService.beginTx()
## Create stub
#set($newWI = $tpro.createWorkItem(“requirement”))
## Set whatever you want
$newWI.set…
$newWI.set…
$newWI.set…
$newWI.set…
$newWI.setCustomField(…
$newWI.setCustomField(…
$newWI.setCustomField(…
$newWI.setCustomField(…

## Dont forget to save
$newI.save()
## Close transaction
$transactionService.commitTx()

Fin

Polarion – Update Work Item with Wiki page

Problem

  • You want to update a polarion work item with a wiki page
  • (You want to update several work items)

Solution

First, if you have no wiki page, create one.

The following code i use regularly to update a bunch of work items. In this example i update a custom field “test” (type String).

## Get project id
#set($projectId = $doc.getProject($doc.getSpace()))
## Get project object
#set($pro = $projectService.getProject($projectId))
## Get the objects
#set($objects = $trackerService.queryWorkItems($pro, “type:requirement”, “id”)
## Iteration
#foreach($entry in $objects)
## Open Transaction
$transactionService.beginTx()
## Set field
$entry.setCustomField(“test”, $texta)
## Don’t forget to save
$entry.save()
## Transaction commit
$transactionService.commitTx()
#end

Fin

Simple Table Builder for TableLayout for Android

Problem

You want to build a simple table in an Android App.

Sample Code

//Building Table Header
TableLayout tv = TableBuilder.getCleanDefaultTableLayout(
            this, R.id.someID);
TableRow tr = TableBuilder.getDefaultTableRow(this);

String[] ids = {"Column1", "Column2", "Column3", 
            "Column4", "Column5"};
int[] colors = {Color.BLUE, Color.BLUE, Color.BLUE, 
            Color.BLUE, Color.BLUE};
int[] sizes = {15, 15, 15, 15, 15};

TableBuilder.addTextViewsAsTableRow(this, tv, ids, 
            colors, sizes, true);

tv.addView(tr);
TableBuilder.addLineToTable(this, tv, Color.WHITE);

List<T> list = dbMgr.getSomeThing();
Iterator it = list.iterator();

//data rows
while(it.hasNext()) {
    T t = (T) it.next();

    tr = TableBuilder.getDefaultTableRow(this);

    //change here row input
    String[] id = {t.get1(), t.get2(), t.get3(), 
                t.get4(), t.get5()};
    int[] color = {Color.RED, Color.WHITE, Color.WHITE, 
                Color.WHITE, Color.WHITE};
    int[] size = {15, 15, 15, 15, 15};

    TableBuilder.addTextViewsAsTableRow(this, tv, id, 
                color, size, true);
    TableBuilder.addLineToTable(this, tv, Color.BLUE);
}

The result looks like this:
tablebuilder_example

The TableBuilder

You can also download the code from my playground GitHub repository.

import android.app.Activity;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class TableBuilder
{
    //create TableLayout for id
    public static TableLayout getDefaultTableLayout(Activity activity, int id)
    {
        TableLayout tv = (TableLayout) activity.findViewById(id);
        return tv;
    }

    //create TableLayout for id and remove all old views (reset)
    public static TableLayout getCleanDefaultTableLayout(Activity activity, int id)
    {
        TableLayout tv = (TableLayout) activity.findViewById(id);
        tv.removeAllViewsInLayout();
        return tv;
    }

    //createn default TableRow
    public static TableRow getDefaultTableRow(Activity activity)
    {
        TableRow tr = new TableRow(activity);
        tr.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
        return tr;
    }

    //add textview to row
    public static void addTextViewToTableRow(Activity activity, TableRow tr, String text, int textColor, int textSize, boolean padding)
    {
        if(activity != null && tr != null) {
            TextView b = new TextView(activity);
            if(text != null)
                b.setText(text);
            if(textColor > 0)
                b.setTextColor(textColor);
            if(textSize > 0)
                b.setTextSize(textSize);
            if(padding)
                b.setPadding(10, 0, 0, 0);
            tr.addView(b);
        }
    }

    //add multiple textviews to row
    public static void addTextViewsAsTableRow(Activity activity, TableLayout tv, String[] texts, int[] colors, int[] sizes, boolean padding)
    {
        if(activity != null && tv != null && texts.length==colors.length && texts.length==sizes.length)
        {
            TableRow tr = getDefaultTableRow(activity);
            for(int i = 0; i < texts.length; i++) {
                addTextViewToTableRow(activity, tr, texts[i], colors[i], sizes[i], padding);
            }
            tv.addView(tr);
        }
    }

    //add a horizontal line to the table (used to separate two rows)
    public static void addLineToTable(Activity activity, TableLayout tl, int color)
    {
        final View vline = new View(activity);
        vline.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 2));
        vline.setBackgroundColor(color);
        tl.addView(vline);
    }
}

Collections in Polarion

Problem

  • For some reason you need a java.util.Set (f.i. HashSet) or a simple java.util.List (f.i. ArrayList).
  • In Polarion Classic Wiki Pages you can’t instantiate Java Collections by your own.

Solution

To obtain a collection you have to steal it. Since you can’t write

#set($test = new java.util.ArrayList())

you have to use a trick to get a fresh collection. Some of the Polarion services and objects are returning Java collections. Thus you only have to force them return an empty collection. Below you will find two examples (HashSet and ArrayList) for this solution.

Obtain a clean java.util.HashSet<IWorkItem>

In some cases i need a free of duplicates list by simply using a Set. To get a Set/HashSet I use the method filterWorkItems from IModule. For a clean HashSet I use a senseless lucene query. For a valid instance of a IModule I just search for a WorkItem.

##Example Code for retrieving a workitem
#set($proId = "ExampleProjectID")
#set($wiId = "WorkItemID")
#set($pro = $projectService.getProject($proId))
#set($tpro = $trackerService.getTrackerProject($pro))
#set($WIobject = $tpro.getWorkItem($wiId))

##Getting a HashSet
#set($hs = $WIobject.getModule().filterWorkItems(“status:YYY”))

##Add an item to the HashSet
#set($bla = $hs.add($someWorkItem))

Obtain a clean java.util.ArrayList<IWorkItem>


##Getting an ArrayList
#set($al = $WIobject.getModule().getExternalWorkItems())

Other instances of Collection

If you need Collections with different generic types you should simply use Google (or your prefered search engine).

Java and Powershell

Problem

  • Getting process id for specific Java application
  • Kill Java applications
  • Monitoring Java applications

Process id

For this purpose, JPS – Java Virtual Machine Process Status Tool (Documentation) – is quite helpful. It can be found in the bin folder of the JDK/JRE. The following example shows the output while running Android Studio.

PS C:\Program Files\Java\jdk1.7.0_xx\bin> jps -v
9196  -Xms256m -Xmx1280m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=225m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Djna.nosys=true -Djna.boot
.library.path= -Djna.debug_load=true -Djna.debug_load.jna=true -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -XX:+HeapDumpOnOutOfMemoryError -Didea
.paths.selector=AndroidStudioPreview1.4 -Didea.platform.prefix=AndroidStudio -Djb.vmOptions=C:\dev2\android-studio-1.4-beta2\bin\studio64.exe.vmoptions -Xbootclass
path/a:C:\dev2\android-studio-1.4-beta2\lib\boot.jar -Didea.jre.check=false
7072 GradleDaemon -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=windows-1252 -Duser.country=DE -Duser.language=de -Duser.variant
4304 Jps -Dapplication.home=C:\Program Files\Java\jdk1.7.0_79 -Xms8m

With the option “-v”, you get all arguments passed to the JVM, which is helpful to select the correct application. To get the process id from the Android Studio, we first have to select the line for Android Studio with the grep-like command select-string and store it in a variable $javaActive. As the selector -Didea.platform.prefix=AndroidStudio is used:

PS C:\Program Files\Java\jdk1.7.0_xx\bin> $javaActive = jps -v | select-string "-Didea.platform.prefix=AndroidStudio"
$javaActive

9196  -Xms256m -Xmx1280m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=225m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Djna.nosys=true 
-Djna.boot.library.path= -Djna.debug_load=true -Djna.debug_load.jna=true -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true 
-XX:+HeapDumpOnOutOfMemoryError -Didea.paths.selector=AndroidStudioPreview1.4 -Didea.platform.prefix=AndroidStudio 
-Djb.vmOptions=C:\dev2\android-studio-1.4-beta2\bin\studio64.exe.vmoptions -Xbootclasspath/a:C:\dev2\android-studio-1.4-beta2\lib\boot.jar -Didea.jre.check=false

In a second step, we have to extract the process id using some simple string operations (searching for the first blank):

PS C:\Program Files\Java\jdk1.7.0_xx\bin> $javaActive = jps -v | select-string "-Didea.platform.prefix=AndroidStudio"
Write-host $javaActive.ToString().Substring(0,$javaActive.ToString().IndexOf(" "))
9196

Kill Java applications

After we successfully got the process id, we now can kill a specific Java application (example Android Studio):

$javaActive = jps -v | select-string "-Didea.platform.prefix=AndroidStudio"
Stop-Process $javaActive.ToString().Substring(0,$javaActive.ToString().IndexOf(" "))

To kill all java applications do the following:

Stop-Process -processname *java*
Stop-Process -processname *jp2launcher*

(jp2launcher is needed for Java Web Start applications.)

Monitoring Java applications

If you want to constantly check if a specific Java application is running and store the result in the windows log, you should do the following.
Register a source in the Windows application log (run as admin):

New-EventLog -LogName Application -Source "My Application"

The checker script (example Android Studio):

$javaActive = jps -v
if($javaActive -like "*-Didea.platform.prefix=AndroidStudio*")
{
 Write-EventLog -LogName Application -Source "My Application" -EntryType Information -EventID 1  -Message "Application is running."
}
else
{
 Write-EventLog -LogName Application -Source "My Application" -EntryType Error -EventID 2  -Message "Application is not running."
 Optional: code to restart
}