想试一下动态编译的功能,所以想看一下java如何编译

原文见:http://www.cnblogs.com/flashsun/p/7246260.html

 

但这篇文章有些错误及遗漏之处,导致有些没有办法编译通过。

我只管我自己这部分了,我是要写一个jar引用外部jar的案例

首先也是写个hello.java 和tom.java,用hello引用tom中的类,当时tom也放在package com;之下,同时注意文件夹也应该如此,tom.java也要放在com文件夹中

在hello.java的文件夹中,用命令

javac -sourcepath . -classpath . hello.java -d target -verbose

 

这样 target目录 就有相应的文件了,包括目录 

 

然后用在 target目录用命令 

jar -cvf tom.jar  ./com/*  把tom编译好成jar,会生成在target目录上

文件清单配置如下

Manifest-Version: 1.0
Created-By: 1.8.0_171 (Oracle Corporation)
Main-Class: Hello
Class-Path: tom.jar

 

 

然后继续用

jar -cvfm hello.jar .\META-INF\MENIFEST.MF * 

 

然后会生成hello.jar

 

然后试用

 

java -jar hello.jar

完成,收工

 

但感觉动态编译没什么用武之地啊,太年轻了。

相关文章:

  • 2022-12-23
  • 2021-09-11
  • 2021-10-12
  • 2021-05-03
猜你喜欢
  • 2022-01-05
  • 2022-01-05
  • 2021-07-04
  • 2021-06-30
  • 2021-08-20
  • 2022-12-23
  • 2018-01-11
相关资源
相似解决方案