Configure the size of the icon at J2ME Polish - java

How can I configure the size of the icon to fit correctly on the multiple mobile devices?
Based on the J2ME Polish documentation, I'm using the following resources folder structure:
IconSize.15x15\icon.png
IconSize.16x16\icon.png
...
But it's no working, I've tried in several mobile devices and all of them load the default J2ME Polish icon.
Here's my build.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myProject" default="j2mepolish">
<property name="polish.home" location="C:\Program Files (x86)\J2ME-Polish" />
<property name="wtk.home" location="C:\JavaME_SDK" />
<taskdef
name="j2mepolish"
classname="de.enough.polish.ant.PolishTask"
classpath="${polish.home}/lib/enough-j2mepolish-build.jar"
/>
<target name="run">
<j2mepolish>
<info
name="My Project"
version="1.0.0"
description="My Project"
vendorName="Diogo"
jarName="myProject.jar"
/>
<deviceRequirements>
<requirement name="Term" value="polish.api.wmapi" />
<requirement name="Identifier" value="Generic/AnyPhone" />
</deviceRequirements>
<build
usePolishGui="true">
<libraries>
<library file="lib/json-1.0.jar" />
</libraries>
<midlet class="myProject" />
<resources
dir="resources/"
defaultexcludes="yes"
excludes="readme.txt" >
<root dir="resources/" includeSubDirs="true" includeBaseDir="true" />
</resources>
<variables>
<variable name="polish.usePolishTitle" value="true" />
<variable name="polish.TextField.suppressCommands" value="true" />
<variable name="polish.TextField.useDirectInput" value="true" />
<variable name="polish.TextField.showInputInfo" value="false" />
</variables>
<obfuscator name="ProGuard"></obfuscator>
<postcompiler name="java5" />
</build>
<emulator />
</j2mepolish>
</target>
<target name="clean">
<delete dir="build" />
<delete dir="dist" />
</target>
</project>

Java ME application icon is defined on Jad and Manifest keys. It is often informed in both MIDlet-Icon and the second value of MIDlet-1. See this other question about it add icon to j2me application. And also see this other questions on icon sizes Is there a standard icon size and color depth for J2ME?.
On the link you provided http://www.enough.de/products/j2me-polish/documentation/building/resource-handling/resource-assembling.html there is this text: "You can use the IconSize.0x0 for storing icon resources for devices with an unknown IconSize capability"
I suggest you, by my personal experience with icons - not with polish - to add a 32x32 png icon image at this folder.

Related

IzPack Shortcut Nightmare

I'm at my wit's end with this.
I have a VERY simple installation descriptor for izpack for a two-package Java app on Windows. Everything works as intended EXCEPT for the shortcut creation. The shortcut panel doesn't seem right, for a start. The label "ShortcutPanel.regular.startup" is displayed instead of "run at startup" or anything of the sort in the startup execution checkbox.
After running the installer, the shortcuts simply aren't created. Here's what my install.xml looks like, it's pretty straightforward:
<izpack:installation version="5.0"
xmlns:izpack="http://izpack.org/schema/installation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://izpack.org/schema/installation http://izpack.org/schema/5.0/izpack-installation-5.0.xsd">
<info>
<appname>application_name</appname>
<appversion>2.0.0</appversion>
<appsubpath>myapp</appsubpath>
<javaversion>1.8</javaversion>
</info>
<locale>
<langpack iso3="bra" />
</locale>
<resources>
<res src="shortcutSpec.xml" id="shortcutSpec.xml"/>
</resources>
<variables>
<variable name="TargetPanel.dir.windows" value="C:/Sistemas"/>
</variables>
<guiprefs width="800" height="600" resizable="no">
<laf name="substance">
<os family="windows" />
<os family="unix" />
<param name="variant" value="mist-silver" />
</laf>
<modifier key="useHeadingPanel" value="yes" />
</guiprefs>
<panels>
<panel classname="HelloPanel" />
<panel classname="DefaultTargetPanel" />
<panel classname="ShortcutPanel" />
<panel classname="InstallPanel" />
<panel classname="FinishPanel" />
</panels>
<natives>
<native type="izpack" name="ShellLink.dll">
<os family="windows"/>
</native>
<native type="izpack" name="ShellLink_x64.dll">
<os family="windows"/>
</native>
</natives>
<packs>
<pack name="Pack1" required="yes">
<description>one of the packs it's a jar</description>
<file src="lib/pack1.jar" targetdir="$INSTALL_PATH/pack1subdir"
override="true">
</file>
<file src="imagens/logo.ico" targetdir="$INSTALL_PATH/pack1subdir/imagens/"
override="true" />
<executable targetfile="lib/pack1.jar" type="jar"
stage="never"></executable>
</pack>
<pack name="Pack2" required="yes">
<description>the other pack</description>
<file src="lib/pack2.jar" targetdir="$INSTALL_PATH/pack2subdir"
override="true">
</file>
<file src="imagens/update.ico" targetdir="$INSTALL_PATH/pack2subdir/imagens/"
override="true" />
<executable targetfile="lib/pack2.jar" type="jar"
stage="never"></executable>
</pack>
</packs>
Then there's the shortcutSpec.xml. My pom moves it to my staging directory:
<izpack:shortcuts version="5.0"
xmlns:izpack="http://izpack.org/schema/shortcuts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://izpack.org/schema/shortcuts http://izpack.org/schema/5.0/izpack-shortcuts-5.0.xsd">
<lateShortcutInstall />
<shortcut name="pack1" programGroup="false"
desktop="true" applications="false" startMenu="no" startup="true"
target="java -jar $INSTALL_PATH/pack1subdir/pack1.jar"
workingDirectory="$INSTALL_PATH/pack1subdir/">
<createForPack name="pack1" />
</shortcut>
<shortcut name="pack2" programGroup="false"
desktop="true" applications="false" startMenu="no" startup="true"
target="java -jar $INSTALL_PATH/pack2subdir/pack1.jar"
workingDirectory="$INSTALL_PATH/pack2subdir/">
<createForPack name="pack2" />
</shortcut>
The installer simply doesn't create any shortcuts anywhere. It finishes with no error messages no logs no stack traces no nothing.
Help.
I fixed that by going into the izPack/lib/izpack-core-5.0.9.jar and opening the /com/izforge/izpack/bin/langpacks/installer/ folder in it. Then editing the bra.xml file and adding the following line:
<str id="ShortcutPanel.regular.startup" txt="Iniciar com o Windows"/>
Then save and update the file in the jar and rebuild your instalation.

Build one jar per platform for multi-platform SWT application

There are a couple of questions to this topic already, but none of them seem to work properly.
Here is a list of them:
Bulding an multi-platform SWT application using Ant
Build multi-platform executable for a SWT application (Eclipse)
Build multi-platform executable for a SWT application using maven
SWT jar for different platform
Create cross platform Java SWT Application
My requirement is to build an ant script that creates one jar per platform, i.e. one for Windows x86, one for Windows x64, Linux x86/x64 and so on.
Does anyone have any further insight?
Using the aforementioned methods, I was not able to produce a workable solution. It either ended with the SWT jar file not automatically being loaded or it not being included in the classpath.
If someone can come up with a working example (ideally including the complete source code), that would be grand!
Right, so I finally came up with a solution that I successfully tested on three platforms.
The two magic components are the jar-in-jar-loader and a proper build script.
The build script with comments can be found here:
<project name="RandomApp" basedir="." default="clean-build">
<property name="src.dir" value="src" />
<!-- Define the necessary paths -->
<property name="build.dir" value="bin_temp" />
<property name="lib.dir" value="lib" />
<property name="lib.deploy.dir" value="lib_swt" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="jar.dir" value="${build.dir}/jar" />
<property name="img.dir" value="img" />
<property name="res.dir" value="res" />
<!-- Define the main class -->
<property name="main-class" value="org.baz.desktop.randomapp.gui.RandomApp" />
<path id="base-classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<!-- Define the class path -->
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
<fileset dir="${lib.deploy.dir}" includes="**/swt_win32_x64.jar" />
</path>
<!-- Clean previously built files -->
<target name="clean">
<delete dir="${build.dir}" />
</target>
<!-- Compile the project -->
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false" />
</target>
<macrodef name="createclasspath">
<attribute name="name" />
<attribute name="swtlib" />
<sequential>
<pathconvert property="#{name}.classpath" pathsep=" ">
<path refid="base-classpath" />
<fileset dir="${lib.deploy.dir}" includes="**/swt_#{swtlib}.jar" />
<mapper>
<chainedmapper>
<flattenmapper />
<globmapper from="*.jar" to="*.jar" />
</chainedmapper>
</mapper>
</pathconvert>
</sequential>
</macrodef>
<!-- Define classpath and create the jar folder -->
<target name="pre_jar" depends="compile">
<!-- Linux 32bit -->
<createclasspath name="win86" swtlib="win32_x86" />
<!-- Linux 64bit -->
<createclasspath name="win64" swtlib="win32_x64" />
<!-- Windows 32bit -->
<createclasspath name="linux86" swtlib="linux_gtk_x86" />
<!-- Windows 64bit -->
<createclasspath name="linux64" swtlib="linux_gtk_x64" />
<!-- MacOS 32bit -->
<createclasspath name="macos86" swtlib="macos_x86" />
<!-- MacOS 64bit -->
<createclasspath name="macos64" swtlib="macos_x64" />
<mkdir dir="${jar.dir}" />
</target>
<macrodef name="createjar">
<attribute name="swtlib" />
<attribute name="swtclasspath" />
<sequential>
<jar destfile="${jar.dir}/${ant.project.name}_#{swtlib}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
<attribute name="Rsrc-Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="." />
<attribute name="Rsrc-Class-Path" value="./ #{swtclasspath}" />
</manifest>
<zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />
<zipfileset dir="${lib.deploy.dir}" includes="**/swt_#{swtlib}.jar" />
<zipfileset dir="${lib.dir}" includes="**/*.jar" excludes="**/jar-in-jar-loader.jar" />
</jar>
</sequential>
</macrodef>
<!-- Create the jar files -->
<target name="jar" depends="pre_jar">
<!-- Linux 32bit -->
<createjar swtlib="linux_gtk_x86" swtclasspath="${linux86.classpath}" />
<!-- Linux 64bit -->
<createjar swtlib="linux_gtk_x64" swtclasspath="${linux64.classpath}" />
<!-- Windows 32bit -->
<createjar swtlib="win32_x86" swtclasspath="${win86.classpath}" />
<!-- Windows 64bit -->
<createjar swtlib="win32_x64" swtclasspath="${win64.classpath}" />
<!-- MacOS 32bit -->
<createjar swtlib="macos_x86" swtclasspath="${macos86.classpath}" />
<!-- MacOS 64bit -->
<createjar swtlib="macos_x64" swtclasspath="${macos64.classpath}" />
</target>
<target name="clean-build" depends="clean,jar" />
</project>
What it basically does is define a base classpath without any SWT library.
Then it creates platform specific classpaths using the base one and adding the appropriate platform SWT library.
The jar task then creates a separate jar for each platform using these classpaths and the jar-in-jar-loader.
And that's it, a fully automated way of generating jars for each (supported) platform.
I've created an example project that people can download and test out. It's an easy starting point for a multi-platform application.
https://www.dropbox.com/s/ianrbl4bn0fmsdi/SWTApplication.7z
Update:
I've managed to significantly shorten the ant script by making proper use of macrodef :)

ANT - How i cant move File to JAR

i've had edited my ANT build process. Here is my working list:
create a copy of the src folder and a selfwritten AntTask Obfuscated all Strings
ANT creates an JAR with <jar>
the JAR will be Obfuscated by ProGuard
An additional file will must be copied to the JAR
JAR will be signed
The bodled step is my Question. How i can copy a single file to the root directory of the JAR. I must make this step here! Before or after won't work: Before: ProGuard will be try to obfuscate this file and gives Exceptions. After cant work, the file must be signed.
Anyone have an smart idea?
Here a minified version of my ANT build script:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<project basedir="." default="default" name="DEMO">
<property environment="env" />
<property name="debuglevel" value="source,lines,vars" />
<property name="target" value="1.7" />
<property name="source" value="1.7" />
<!-- Applet Informationen -->
<property name="version" value="1.0.0" />
<!-- Start Build process -->
<target name="default">
<echo message="Copy source" />
<delete dir="builds/temp/" />
<mkdir dir="builds/temp/" />
<copydir src="src" dest="builds/temp/" />
<echo message="Obfuscate Strings" />
<taskdef resource="task.properties" classpath="libs/MyStringHelper.jar" />
<mystringhelper dir="builds/temp/" name="_X.class" decoder="MyClass.myMethod" imports="import test.MyClass;" />
<javac srcdir="builds/temp/" destdir="bin" />
<sleep seconds="1" />
<echo message="Create JAR Archive with Version ${version}" />
<jar destfile="builds/${name}${version}.jar" basedir="bin">
<manifest>
<attribute name="Application-Name" value="${name}" />
<attribute name="Application-Library-Allowable-Codebase" value="*.domain.com localhost" />
<attribute name="Caller-Allowable-Codebase" value="*.domain.com localhost" />
<attribute name="Codebase" value="*.domain.com localhost" />
<attribute name="Permissions" value="all-permissions" />
<attribute name="Author" value="Adrian Preuss" />
<attribute name="Main-Class" value="main.Run" />
</manifest>
</jar>
<echo message="Obfuscate the Archive" />
<taskdef resource="proguard/ant/task.properties" classpath="libs/proguard.jar" />
<proguard printmapping="proguard.map" overloadaggressively="off" repackageclasses="" renamesourcefileattribute="SourceFile">
<injar file="builds/${name}${version}.jar" />
<outjar file="builds/__${name}${version}.jar" />
<libraryjar file="${java.home}/lib/rt.jar" />
<libraryjar file="libs/ant.jar" />
<libraryjar file="libs/gradle-plugins-1.3.jar" />
<libraryjar file="libs/gradle-base-services-1.3.jar" />
<libraryjar file="libs/gradle-core-1.3.jar" />
<libraryjar file="libs/groovy-all-1.8.6.jar" />
<libraryjar file="libs/kenv.zip" />
<keeppackagename name="main" />
<keep access="public" name="main.Run">
<method access="public" type="void" name="changeLanguage" parameters="java.lang.String" />
</keep>
</proguard>
<delete file="builds/${name}${version}.jar" failonerror="false" />
<move file="builds/__${name}${version}.jar" tofile="builds/${name}${version}.jar" />
<!--
##
## ADD the File "builds/temp/_XA.class" to the JAR
##
## Info: the _XA.class is'nt an Java-Class file!
-->
<echo message="Roll up the code signing" />
<signjar jar="builds/${name}${version}.jar" alias="${name}" keystore="${name}.keystore" storepass="${password}" preservelastmodified="true" />
<echo message="Verify code signing" />
<verifyjar jar="builds/${name}${version}.jar" alias="${name}" storepass="${password}"/>
<echo message="Copy applet to local environment" />
<copy file="builds/${name}${version}.jar" tofile="C:/devsrv/htdocs/${name}${version}.jar" failonerror="false" />
<echo message="Cleanup,..." />
<!-- .... -->
</target>
</project>
This is a part from my ant build file including all xml, jpg, gif and png:
<!-- ============================================================== -->
<!-- Build application -->
<!-- ============================================================== -->
<target name="build" depends="make-bin-dir" description="Build application">
<javac srcdir="${src.dir}" destdir="${bin.dir}" debug="on" classpathref="javac.classpath" />
<copy todir="${bin.dir}">
<fileset dir="${src.dir}">
<include name="**/*.xml" />
<include name="**/*.jpg" />
<include name="**/*.gif" />
<include name="**/*.png" />
</fileset>
</copy>
</target>
To only include one file just put the full name in include name= "fullnamehere" />
Sorry...haven't seen your part to add...
Try it like this:
include name= "builds/temp/_XA.class" />
Since a Jar is really a Zip file, you could unzip the jar to a temp directory after proguard does its thing, add the _XA.class file where you want in in that temp dir, and re-create the jar file before signing.

Define constants before init in ant/netbeans

I have a webapp to be ran on Tomcat6/JbossAS 5 and, for versioning purposes, I have several AND targets that will perform a set of operations to define a constant with version number and build datetime.
The targets perform the following:
Delete the Release.java
Copy the Release.template to Release.java with the versioning info properly set as a constant (public static final String)
The thing is that, the constant references are replaced on the code before compilation. For instance, where I have
log.debug("Release: " + Release.info);
I can see, using java decompiler, the following (let's assume that "TO_BE_DEFINED" is the initial value for Relase.info):
log.debug("Release: TO_BE_DEFINED");
The targets are the following:
<target name="build-config" >
<!-- config -->
<property name="project.name" value="MY PROJECT" />
<property name="release.prefix" value="MPROJECT" />
<property name="release.num" value="1.0" />
<property name="release.info.file.path" value="org/my/project/Release" />
<tstamp>
<format property="release.date" pattern="yyyy-MM-dd HH:mm:ss z" />
</tstamp>
<!-- end config -->
<property name="release.version" value="${release.prefix}-${release.num}" />
<property name="release.info" value="${release.version} ${release.date}" />
</target>
<target name="build-replace">
<filter token="release.info" value="${release.version} ${release.date}" />
<delete file="${src.dir}/${release.info.file.path}.java" />
<copy file="${src.dir}/${release.info.file.path}.template" tofile="${src.dir}/${release.info.file.path}.java" filtering="true" />
</target>
<target name="build-myproj-1.0.jar" depends="init,buil-config,build-replace,compile">
<mkdir dir="${dist.dir}"/>
<jar compress="true" jarfile="${dist.dir}/MPROJECT-1.0.jar">
<fileset dir="${build.classes.dir}"
excludes="META-INF/*.*, WEB-INF/classes/*.xml"
includes="**/*.class"
/>
<manifest>
<section name="${project.name}">
<attribute name="Release-Version" value="${release.version}" />
<attribute name="Release-Date" value="${release.date}" />
</section>
</manifest>
</jar>
</target>
and my class is defined as
public abstract class Release {
/** Release info */
public static final String INFO = "TO_BE_DEFINED";
}
I understand that this may be a little bit confusing and if I'm missing some information please feel free to ask
Compile-time constants are replaced in client code when the client code is compiled.
To get the client code to pick up the new value of the constant, either recompile everything, replace the field with a getter, or use one of the strategies from this question

how to compile ResourceBundle class using build.xml file

I have developed J2ME application.
When I try to compile my application via build.xml file I get below error
"D:\sakina\TTMF_Project\TTMFMobileClient\src\ConfigurationUtil.java:3: cannot find symbol
[javac] symbol : class ResourceBundle
[javac] location: package java.util
[javac] import java.util.ResourceBundle;
[javac] ^"
Can anyone tell me if I have to add anything in my build.xml file
<!-- define the installation folder of J2ME Polish -->
<property name="polish.home" location="C:\Program Files\J2ME-Polish" />
<!-- define the installation folder of the WTK -->
<property name="wtk.home" location="C:\WTK2.5.2_01" />
<property name="device" value="Generic/midp2cldc11" />
<property name="devices" value="${device},Generic/AnyMsaPhone,Nokia/Series40E3,Nokia/Series60E3,Sony-Ericsson/JavaPlatform7,Sony-Ericsson/JavaPlatform8"/>
<!-- define the J2ME Polish task, classpath on one line please -->
<property name="polish.client.source" value="${polish.home}/j2mepolish-src/j2me/src/" />
<taskdef
name="j2mepolish"
classname="de.enough.polish.ant.PolishTask"
classpath="${polish.home}/lib/enough-j2mepolish-build.jar:${polish.home}/lib/jdom.jar" />
<!-- start the build with J2ME Polish -->
<target name="j2mepolish" depends="init">
<j2mepolish>
<info license="GPL" name="TTMFMobile" version="1.0.0" jarname="TTMFMobile.jar" deletenotify="Do you really want to exit?" />
<deviceRequirements>
<requirement name="Identifier" value="${device}" />
</deviceRequirements>
<build usePolishGui="true" fullscreen = "yes">
<midlets>
<midlet name="TMF" class="TTMFMobile" />
</midlets>
<libraries>
<!--<library file="${polish.home}/import/BlackBerry-5.0.0.jar" />-->
<library file="${polish.home}/import/json-1.0.jar" />
</libraries>
<variables includeAntProperties="true" >
<variable name="polish.TextField.showInputInfo" value="false"/>
<variable name="polish.TextField.useDirectInput" value="false" />
<variable name="polish.TextField.suppressDeleteCommands" value="false"/>
<variable name="polish.TextField.suppressClearCommands" value="true"/>
</variables>
<obfuscator name="ProGuard" unless="test or polish.blackberry" />
<resources dir="${resource.dir}" defaultexcludes="yes" excludes="readme.txt">
</resources>
<jad>
<attribute name="MIDlet-Icon" value=""/>
</jad>
</build>
<emulator />
</j2mepolish>
</target>
<target name="clean">
<delete dir="build" />
<delete dir="dist" />
</target>
<target name="init">
<property name="resource.dir" value="res" />
<property name="path.deploy" value="deployed"/>
</target>
ConfigurationUtil.java file::
public class ConfigurationUtil {
private static ResourceBundle objResourceBundle = ResourceBundle.getBundle("ApplicationResources");
public static String getConfigValue(String configName){
String configValue = objResourceBundle.getString(configName);
return configValue;
}
}
You need to check your code in ConfigurationUtil.java
There is a compilation occuring in this file during the build . Fix the error and rebuild it should work .

Categories