您的位置:首页 > 编程语言 > Java开发

Symbian程序如何安装jar,并启动java程序参考资料

2008-11-12 22:34 633 查看
Nokia论坛技术资料Symbian解决方案-中文版:
http://discussion.forum.nokia.com/forum/showthread.php?t=60202&highlight=RApaLsSession

可参考帖子如下:
http://discussion.forum.nokia.com/forum/showthread.php?t=98014
http://discussion.forum.nokia.com/forum/showthread.php?t=87919

http://discussion.forum.nokia.com/forum/showthread.php?t=73399

http://discussion.forum.nokia.com/forum/showthread.php?t=16862&highlight=kmidrun

To see how DocumentHandler works - check FileList example application or the SDK help.

TSS000465 - Launching MIDlets programmatically on S60 3rd Edition

http://wiki.forum.nokia.com/index.php/TSS000465_-_Launching_MIDlets_programmatically_on_S60_3rd_Edition

http://discussion.forum.nokia.com/forum/showthread.php?t=116102
http://wiki.forum.nokia.com/index.php/Launching_a_midlet_from_symbian_C++_code

稍微总结一下:

1.安装:

OpenFileEmbeddedL函数

通过 RApaLsSession 调用 midp2.exe程序,然后达到给一系列的参数调用目标jar文件
jar 程序是通过midp2线程调用的,在真机上的调用格式是:
midp2.exe -jar "c:/system/midlets/[***]/**.jar -msid 2 -msin 1 -mid1
在3.0机器上就是midp2.exe -jar /private/102033E6/MIDlets/[***]/**.jar -msid 2 -msin 1 -mid1 是么?

是的,所有的jar程序也就是java都是用kvm调用的,当它运行时,你会看到midp2被载入了内存。

kmidrun.exe方法调用java程序是针对S60 1st来说的,而在S60 2nd中就要使用新的方法,因为在第二版中,java都是做为一个独立程序来安装的,安装后的路径就在/system/apps中,而它的app名就是一个UID数字,如[101aaebb].app,而你需要做的就是通过调用app程序的方法去调用它,这样就能启动这个java程序了。

具体调用app程序的方法,请参考:
#include <EikDll.h>
#include <apacmdln.h>
...
_LIT(KMyAppName, "c://system//Apps//MyApp//MyApp.app");
_LIT(KMyDocName, "c://Documents//MyApp.dat");

CApaCommandLine * cmd=CApaCommandLine::NewL();
cmd->SetLibraryNameL(KMyAppName);
cmd->SetDocumentNameL(KMyDocName);
cmd->SetCommandL(EApaCommandRun);
EikDll::StartAppL(*cmd);

OK,解决了.之前不行是因为我用EikDll::StartAppL(*cmd);
改成
RApaLsSession ras;
.
.
.
ras.StartApp( *cmd );
就可以了.谢谢各位了

http://discussion.forum.nokia.com/forum/showthread.php?t=16862&highlight=kmidrun

Here's how I do it in UIQ, should be the same for S60:

---------------------------------
RApaLsSession appSession;

if( appSession.Connect() == KErrNone &&
appSession.GetAllApps() == KErrNone ){
TApaAppInfo appInfo;
TInt result = KErrNone;
TInt handeled = 0;
TInt count = 0;
TBuf<256> appPath( _L("") );
TBuf<64> appName;

// Find the path to the midlets app file, that gets created
// when the midlet is installed
while( result != RApaLsSession::ENoMoreAppsInList ){
if( result == KErrNone )
result = appSession.GetNextApp( appInfo );

// GetNextApp ocasionally fails, hence the use of
// handeled and count.
if( result == KErrNone && count == handeled ){
handeled++;
count++;
appName.Copy( appInfo.iCaption );
if( appName.Compare( _L("<Midlet app name") ) == 0 ){
// Found the app we we're looking for.
appPath.Copy( appInfo.iFullName );
result = RApaLsSession::ENoMoreAppsInList;
}
}
else if( result == RApaLsSession::EAppListInvalid ){
// Something failed, so the session is restarted.
count = 0;
appSession.Close();
if( appSession.Connect() == KErrNone &&
appSession.GetAllApps() == KErrNone )
result = KErrNone;
}
}
CApaCommandLine * cmd=CApaCommandLine::NewL();
cmd->SetLibraryNameL( appPath );
cmd->SetCommandL(EApaCommandRun);
// Start the midlet
if( appSession.StartApp(*cmd) == KErrNotFound )
ShowErrorDialog( _L("MIDLET not found") );
}
else{
ShowErrorDialog( _L("Failed to search for MIDLET") );
}
appSession.Close();

-----------------------------------------------------------------------------

Our application after downloading the JAD file will save it to the local folder and passes it for the Midlet installation using CdocumentHandler. This works fine when the JAD file contains the full path for the JAR.

/*

Here is a simple example code for executable (.exe) application that launches a
midlet and exits. This is done by starting a new process for virtual machine.
The information about the midlet to be launched is passed to the VM as a command
line parameter which has a specific format.

The command line consists of tcp/ip port reserved for the midlet, a midlet uid,
midlet name, and the location (drive,path and name) of midlet jar and jad files.
These are separated by asterisks ('*'). If the jad/jar contains more than one
midlets, the one to be launched is determined by the midlet name parameter.

In this example, the launched midlet (Helloworld) files are located in
c://system//apps//MidLaunch//

NOTES:

- This is NOT a recommended way to launch midlets from native applications,
but currently the only way.

- The example code here works only in the target device, NOT in the emulator.

The main problems with this method are:

- A new instance of virtual machine is started for each midlet. Normally, the
MidpUI application uses the same KVM instance for all midlets from the same
midlet suite.

- The port used for midlet is hardcoded. Normally, the launching application
(MidpUI) runs a search to find a free port.

- This example does not rename the launched process according to convention
used in Midp environment. This may cause problems if other midlets are
launched via MidpUI at the same time.

- Using hardcoded values for KVM location and command line syntax will
probably fail if/when there are changes to the platform.
*/

//------------------------------------------------------------------------------
// A simple example (.exe) launching a midlet (Helloworld) from C++ code

#include <e32base.h>
#include <e32std.h>

const TInt KMaxCommandLine = 1024;
const TInt KMidletPort = 7049;
const TInt KMidletUidValue = 0x100009c4;
const TUid KMidletUid = {KMidletUidValue};

LOCAL_C void doLaunchL();

// midlet name
_LIT(KMidletName, "HelloWorld");

// KVM virtual machine location on ROM drive
_LIT(KMidRunROMLocation, "z://system//programs//kmidrun.exe");

// location of jad + jar
_LIT(KMidletJadLocation, "c://system//apps//MidLaunch//HelloWorld.jad");
_LIT(KMidletJarLocation, "c://system//apps//MidLaunch//HelloWorld.jar");

// main function called by E32
GLDEF_C TInt E32Main()
{
_LIT(KE32Main, "KE32Main");

__UHEAP_MARK;
CTrapCleanup* cleanup=CTrapCleanup::New(); // get a clean-up stack
TRAPD(error,doLaunchL());

__ASSERT_ALWAYS(!error,User::Panic(KE32Main,error));
delete cleanup; // destroy cleanup stack
__UHEAP_MARKEND;

return 0;
}

// actual launching of a midlet
LOCAL_C void doLaunchL()
{
TBuf<KMaxCommandLine> cmdLine;
_LIT(KSeparator, "*");

// cmd line syntax: PortNumber*MIDletUid*MIDletName*JarLocation*JadLocation*

cmdLine.AppendNum(KMidletPort);
cmdLine.Append(KSeparator);

// append a midlet uid in decimal format to the command line
TBuf<16> uidNum;
uidNum.Num(KMidletUid.iUid,EDecimal);
cmdLine.Append(uidNum);
cmdLine.Append(KSeparator);

// append a midlet name to the command line
cmdLine.Append(KMidletName);
cmdLine.Append(KSeparator);

// append a jar file location to the command line
cmdLine.Append(KMidletJarLocation);
cmdLine.Append(KSeparator);

// append a jad file location to the command line
cmdLine.Append(KMidletJadLocation);
cmdLine.Append(KSeparator);

// create a new process
RProcess process;

TInt error = process.Create(KMidRunROMLocation,cmdLine);
User::LeaveIfError(error);

// TODO: process should be renamed according to convention used with KVM

process.Resume();
process.Close();
}

这是一段完整的调用JAVA的代码,但是是1.0-2.0版本的。请说明一下具体哪些地方需要针对3.0作出修改。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: