---
title: "手动将class打包成jar包方法"
author: "ariyue"
date: "2010-09-10T00:41:59Z"
tags: ["C", "C#", "C++", "DOS"]
categories: ["编程语言"]
slug: "class-jar"
draft: false
lastmod: "2010-09-10T00:41:59Z"
id: 759885
url: "https://ariyue.iteye.com/blog/759885"
---

示例:\[ 自定义的接口,用jar包实现 ] One: Java代码 1. package com.one; 2. 3. public interface Action { 4. 5. public final String HELLO="hello" 6. 7. public String Hello(); 8. 9. } Two: Java代码 1. public class Test implements Action{ 2. 3. public String Hello() { 4. 5. return HELLO; 6. 7. } 8. 9. public static void main(String\[] args) { 10. 11. Test test=new Test(); 12. 13. System.out.println(test.Hello()); 14. 15. } 16. 17. } l 编译One 程序,并打包到com/one 目录下; l 编写\[ @.mf ] 文件,其中@表示任意名称; main-class: com.one.Action \[ 打包成jar的主类 ] 保存为 action.mf \[ 可自行取名 ] l 将第一步所得的文件带目录和第二步所得的文件一起放入一个文件夹 本例放入packaJar文件下 l 在Dos 下进入packJar所在的文件夹 \[ 本例文件夹放在c:/packJar,可以任意位置 ] C:\\Documents and Settings\\admin&gt;cd\\ C:\\&gt;cd packJar C:\\packJar&gt;dir 2009-02-17 16:22 action.mf 2009-02-17 16:51 com C:\\packJar&gt; l C:\\packJar&gt;jar cfm Action.jar action.mf com/one/\*.class Jar:打包命令 Cfm:参数 Action.jar:欲打成包的jar包名 \[ 任意名 ] Action.mf:…… Com/one/\*.class:将com/one文件夹下的所有.class文件打入 jar包中 l 成功后得: l 将此jar包路径加入classpath环境变量中 l ---------- 编译 Two ---------- 输出完成 (耗时: 0 秒) - 正常终止 l ---------- 运行 ---------- hello 输出完成 (耗时: 0 秒) - 正常终止 l 打包,测试成功!