将Java代码打包为exe文件
原文来自:http://gocom.primeton.com/modules/newbb/item44444_44444.htm
1 基本信息
摘要:
现在有很多的工具将Java代码打包为exe文件,执行时不需要再编写批处理文件,或者在命令行输入长长的classpath信息,为用户使用提供了很大的方便。这也是很多商业软件常常使用的方法。
作者:晏斐
2 将Java代码打包为exe文件
现在有很多的工具将Java代码打包为exe文件,执行时不需要再编写批处理文件,或者在命令行输入长长的classpath信息,为用户使用提供了很大的方便。这也是很多商业软件常常使用的方法。
将Java代码打包为exe文件,一般需要两个步骤:
1. 编写本地代码,创建虚拟机,加载并执行Main Class。
2. 将Java代码打包为jar文件,并与本地代码exe文件合并。
下面的代码,会加载jvm.dll,并调用JNI_CreateJavaVM导出函数创建Java虚拟机,得到JNIEnv指针,然后调用FindClass查找Main Class,之后调用GetStaticMethodID方法得到main方法,并执行main方法。代码如下:
#include <windows.h>
#include <jni.h>
//#pragma comment( linker, "/subsystem:"console" /entry:"mainCRTStartup"" )
#pragma comment( linker, "/subsystem:"windows" /entry:"WinMainCRTStartup"" )
typedef jint (JNICALL *JNICREATEPROC)(JavaVM **, void **, void *);
bool setStream(JNIEnv *env, const char* pszFileName, const char* pszMethod);
//启动java虚拟机方法
//bool main(int argc,char *argv[])
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
...{
//jvm动态库的路径
const char szJvmPath[] = "d:\jdk1.5.0_07\jre\bin\server\jvm.dll";
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
文件对象的生成和文件的创建
/*
* ProcessFileName.java
*
* Created on 2006年8月22日, 下午3:10
*
* 文件对象的生成和文件的创建
*/
package study.iostudy;
import java.io.*;
public class GenerateFile
{
public static void main(String ......
public class FilePath {
public void Print() {
String a = this.getClass().getClassLoader().getResource(".").getPath();
String b = this.getClass().getResource("").getPath();
String c = this.getClass().getResource(" ").getPath();
&n ......
import java.io.FileInputStream;
public class FileCopy{
public static void main(String[] args){
try{
&nb ......