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 .
Related
What is the current best way to distribute an application on a Mac?
What I would like is a build.xml that, when built (in NetBeans) will output an .exe (windows) and .app (mac) into the dist folder.
I currently have a build.xml that compacts the program into a .zip file for distribution, but would like to add an .app and .exe for mac and windows.
Here is my current build.xml that outputs to a zip file.
<?xml version="1.0" encoding="UTF-8"?>
<project name="name" default="default" basedir=".">
<description></description>
<import file="nbproject/build-impl.xml"/>
<property file="version.properties"/>
<property name="version" value="${version.major}.${version.minor}.${version.patch}" />
<property name="executable.name" value="company-${version.product.name}-${version}" />
<target name="-post-jar" description="Generates a versioned name for the JAR file">
<mkdir dir="LOGS" />
<move file="dist/${ant.project.name}.jar" tofile="dist/${executable.name}.jar" />
<antcall target="generate-run-scripts" />
<antcall target="deliverable-osx" />
<antcall target="deliverable-windows" />
</target>
<target name="generate-run-scripts" description="Generate batch files to run the application">
<echo file="dist/run.bat">
java -cp ${executable.name}.jar -Djava.util.logging.config.file=logging.properties -Xmx2048m -Dcom.sun.management.jmxremote classname
</echo>
<echo file="dist/run.sh">#!/bin/sh
java -cp ${executable.name}.jar -Djava.util.logging.config.file=logging.properties -Xmx2048m -Dcom.sun.management.jmxremote classname
</echo>
</target>
<target name="deliverable-windows" description="Deployment files for Windows runtime">
<property name="zip.name" value="Project-${version}-windows" />
<zip destfile="dist/${zip.name}.zip">
<zipfileset file="dist/${executable.name}.jar" />
<zipfileset file="logging.properties"/>
<zipfileset dir="dist/lib" includes="*.jar" prefix="lib" />
<zipfileset file="dist/run.bat"/>
<zipfileset dir="LOGS" excludes="*" />
<zipfileset dir="files" excludes="*" />
<zipfileset file="changelog.txt"/>
</zip>
</target>
<target name="deliverable-osx" description="Deployment files for Apple OS-X runtime">
<property name="zip.name" value="Project-${version}-OSX" />
<zip destfile="dist/${zip.name}.zip">
<zipfileset file="dist/${executable.name}.jar" />
<zipfileset file="logging.properties"/>
<zipfileset dir="dist/lib" includes="*.jar" prefix="lib" />
<zipfileset file="dist/run.sh" filemode="755" />
<zipfileset dir="LOGS" excludes="*" />
<zipfileset dir="files" excludes="*" />
<zipfileset file="changelog.txt"/>
</zip>
</target>
</project>
Here is my attempt at outputting an .app file. It outputs a .app file, but displays an error message every time I try running it. (Although after running it again its not even outputting an .app file).
I used Packaging a Java App to create the build.xml.
<?xml version="1.0" encoding="UTF-8"?>
<project name="name" default="default" basedir=".">
<description></description>
<import file="nbproject/build-impl.xml"/>
<property file="version.properties"/>
<property name="version" value="${version.major}.${version.minor}.${version.patch}" />
<property name="executable.name" value="company-${version.product.name}-${version}" />
<property environment="env" />
<taskdef name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="ai_debug">
<bundleapp outputdirectory="dist"
name="Project"
displayname="Project-${version}"
identifier="classname"
mainclassname="classname">
<runtime dir="${java.home}" />
<classpath file="dist/Project.jar"/>
</bundleapp>
</target>
</project>
I'm trying to access a Java Applet from IE 9. I'm using this code to create the applet:
var attributes = {
id:'idApplet',
code:'some.package.PrintApplet.class',
archive:'Applet.jar',
codebase:'<%=base_url%>/public/jar/',
width:400,
height:400
};
var parameters = {
// Some parameters
};
var version = '1.5' ;
deployJava.runApplet(attributes, parameters, version);
But I'm getting this in my .jsp page:
This is the code of my applet:
public class PrintApplet extends Applet{
// Some parameters
public void init() {
System.out.println("Started");
}
public void useLocalPrinter() {
//some actions
}
}
If anyone has this problem again, it's very simple. I was exporting my JAR from Rational Application Developer (Eclipse based) and it wasn't being recognized by the JRE. I have to use ANT to compile my JAR and the problem was gone.
The ant snippet that i used was this:
<project name="applet" default="jar" basedir=".">
<property name="jar.home" value="${basedir}/lib" />
<property name="src.home" value="${basedir}/src-applet" />
<property name="build.home" value="${basedir}/build-applet" />
<property name="classes.home" value="${build.home}/classes" />
<property name="jar.name" value="wami_audio_applet.jar" />
<property name="jar.path" value="${jar.home}/jar.name" />
<property name="compile.debug" value="true" />
<property name="compile.deprecation" value="false" />
<property name="compile.optimize" value="true" />
<path id="compile.classpath">
<pathelement location="${basedir}/lib" />
</path>
<target name="all" depends="clean, prepare, jar"/>
<target name="clean">
<delete dir="${jar.path}" />
<delete dir="${classes.home}" />
</target>
<target name="prepare">
<mkdir dir="${build.home}" />
<mkdir dir="${jar.home}" />
<mkdir dir="${classes.home}" />
</target>
<target name="compile" depends="prepare">
<mkdir dir="${classes.home}" />
<javac srcdir="${src.home}" destdir="${classes.home}" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}" target="1.5">
<classpath refid="compile.classpath" />
</javac>
</target>
<target name="jar" depends="compile" description="Make the jar">
<jar jarfile="${jar.home}/${jar.name}" basedir="${classes.home}">
</jar>
</target>
</project>
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 :)
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.
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.