Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¶¯Ì¬Éú³ÉjavaÎļþµÄ·½·¨

package com.hongsoft.test;
import java.io.*;
//¶¨ÖƵÄÀà×°ÈëÆ÷
public class TestCompile extends ClassLoader
{
String _compiler;
String _classpath;
public static void main(String[] args)
{
new TestCompile();
}
public TestCompile()
{
super(ClassLoader.getSystemClassLoader());
//ĬÈϱàÒëÆ÷
if (_compiler == null)
_compiler = "D:\\j2sdk1.4.2\\bin\\javac";
_classpath = ".";
String extraclasspath =
"c:\\Program Files\\Java\\j2re1.4.2\\lib\\rt.jar";
// = System.getProperty("calc.classpath");
if (extraclasspath != null)
{
_classpath =
_classpath
+ System.getProperty("path.separator")
+ extraclasspath;
}
compile();
}
public void compile()
{
String filename = "";
String classname = "";
try
{
//´´½¨ÁÙʱÎļþ
File javafile =
File.createTempFile("compiled_", ".java", new File("."));
filename = javafile.getName();
classname = filename.substring(0, filename.lastIndexOf("."));
generateJavaFile(javafile, classname);
//±àÒëÎļþ
invokeCompiler(javafile);
//´´½¨javaÀà
byte[] buf = readBytes(classname + ".class");
Class c = defineClass(buf, 0, buf.length);
try
{
c.newInstance();
}
catch (IllegalAccessException e)
{
throw new RuntimeException(e.getMessage());
}
catch (InstantiationException e)
{
throw new RuntimeException(e.getMessage());
}
}
catch (IOException e)
{
throw new RuntimeException(e.getMessage());
}
}
//Éú³ÉjavaÎļþ
void generateJavaFile(File javafile, String classname) throws IOException
{
FileOutputStream out = new FileOutputStream(javafile);
String text =
"public class "
+ classname
+ " {"
+ " public int getCreater() {return 1;}"
+ "}";
out.write(text.getBytes());
out.close();
}
//±àÒëjavaÎļþ
void invokeCompiler(File javafile) throws IOException
{
String[] cmd =
{ _compiler, "-classpath", _classpath, javafile.getName()};
//Ö´ÐбàÒëÃüÁî
//A1£º
Process process = Run


Ïà¹ØÎĵµ£º

Java¶àÏß³Ì

http://lavasoft.blog.51cto.com/62575/27069
ÊØ»¤Ï̺߳ÍÓû§Ïß³Ì
ÊØ»¤Ïß³ÌÓëÆÕͨÏ̵߳ÄΨһÇø±ðÊÇ£ºµ±JVMÖÐËùÓеÄÏ̶߳¼ÊÇÊØ»¤Ï̵߳Äʱºò£¬JVM¾Í¿ÉÒÔÍ˳öÁË£»Èç¹û»¹ÓÐÒ»¸ö»òÒÔÉϵķÇÊØ»¤Ïß³ÌÔò²»»áÍ˳ö¡££¨ÒÔÉÏÊÇÕë¶ÔÕý³£Í˳ö£¬µ÷ÓÃSystem.exitÔò±Ø¶¨»áÍ˳ö£© 
ËùÒÔsetDeamon(true)µÄΨһÒâÒå¾ÍÊǸæËßJVM²»ÐèÒªµÈ´ ......

javaµÄ¶¨Ê±Æ÷ʹÓ÷½·¨

  java¶¨Ê±Æ÷µÄʹÓÃ
¶¨Ê±Æ÷ÀàTimerÔÚjava.util°üÖС£Ê¹ÓÃʱ£¬ÏÈʵÀý»¯£¬È»ºóʹÓÃʵÀýµÄschedule(TimerTask task, long delay)·½·¨£¬É趨ָ¶¨µÄÈÎÎñtaskÔÚÖ¸¶¨µÄÑÓ³ÙdelayºóÖ´ÐС£¶¨Ê±Æ÷ÈÎÎñÀàTimerTaskÊdzéÏóÀ࣬¼Ì³Ð²¢ÖØдÆärun()·½·¨£¬¿ÉʵÏÖ¾ßÌåÈÎÎñ¡£
schedule(TimerTask task, Date time)É趨ָ¶¨ÈÎÎñtaskÔÚÖ¸ ......

javaÓïÑÔÈçºÎµ÷ÓÃDLL

javaÓïÑÔµ÷ÓÃdllµÄ·½·¨£º
1¡£¼ÓÔØdll£¬±ØÐëÊǾ²Ì¬·½·¨¡£
    static{
System.loadLibrary(DllConstants.DLL_PATH);
  }
2¡£½«dllÖпª·¢µÄ½Ó¿ÚÉùÃ÷Ϊ±¾µØ½Ó¿Ú
   public native String[] getTxt();
   
......

[JAVA]ÐÞ¸ÄJavaÎļþ²»ÓÃÖØÆôTomcat·þÎñµÄ·½·¨

ÐÞ¸ÄJavaÎļþ²»ÓÃÖØÆôTomcat·þÎñµÄ·½·¨
      ÔÚʹÓÃEclipse+Tomcat¿ª·¢JavaÏîÄ¿µÄʱºò³£³£»áÅöµ½ÕâÑùµÄÇé¿ö£¬ÒÑÐÞ¸ÄJavaÎļþTomcat¾Í»á×Ô¶¯ÖØÆô£¬½ÓÏÂÀ´¾ÍÊÇÂþ³¤µÄµÈ´ý·þÎñÖØÆôÍê±Ï¡£ÄÇÆäʵ´ó¶àÊýµÄJavaÎļþÐÞ¸ÄÊÇûÓбØÒªÖØÆô·þÎñµÄ£¬Ö»ÓÐһЩÌض¨µÄJavaÎļþ£¬±ÈÈç˵ֻÓÐÖØÆô·þÎñµÄʱºò²Å»áµ÷Ó ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ