`
java_beginner_liyun
  • 浏览: 73580 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

怎么打jar包 jar怎么运行

阅读更多

一、怎么打jar包

第一步:选中要打jar包的工程

第二步:鼠标右击,选择Export...

第三步:选择java中的Runnable JAR file(如图)



点击“Next” 

第四步:(1)在Launch configuration:选择要打jar包的mian所在的类名;(如图)



 

            (2)在Export destination:选择要存放jar的名称和地址(如图)

 

      (3)如果要打的jar包需要调用别的jar包 请选择Library handling:中copy required libraries into a sub-folder next to the generated JAR(如图)



 第五步:点击 “Finish”

二、运行 jar 方法

(1)cmd

(2)java -jar 盘:\文件名\XXXX.jar

  • 大小: 52.1 KB
  • 大小: 68.7 KB
  • 大小: 77.5 KB
  • 大小: 13.6 KB
分享到:
评论
11 楼 zhoulangqin 2014-11-07  
请问,如果我里面写成循环执行,执行jar包,那要怎么结束
10 楼 liubiaocai 2012-03-02  
感谢LZ,终于搞定了eclipse导出jar,并且在dos里面可以运行了
9 楼 lk617238688 2011-01-25  
8 楼 lk617238688 2011-01-25  
/**
* 遍历目录
*
* @param directoryPath
*/
public static void read(String txtPath, String xmlPath) {
File dir = new File(txtPath);
File[] files = dir.listFiles();
if (files == null) {
return;
} else {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
read(files[i].getAbsolutePath(), xmlPath);
} else {
// read file
readfile2Xml(files[i].getAbsolutePath(), xmlPath);
}
}
}
}

/**
* start()
*
* @param txtPath
* @param xmlPath
* @throws FileNotFoundException
* @throws IOException
*/
private static void start(String txtPath, String xmlPath)
throws FileNotFoundException, IOException {
// 创建XML
bulidXmlDoc(xmlPath);
// 遍历
read(txtPath, xmlPath);
}

public static void main(String[] args) throws FileNotFoundException,
IOException {
// start(args[0], args[1]);
start("F:\\works\\updown\\functions",
"F:\\works\\Java\\workspace\\txtfmtxml\\txtfmtxml.xml");
}
}
7 楼 lk617238688 2011-01-25  
/**
* 读取文件 每行生成一个Element
*
* @param file
*/
private static void readfile2Xml(String file, String xmlPath) {
String fileName = file.substring(file.lastIndexOf("\\") + 1, file
.lastIndexOf("."));
String[] func = null;
String funcName = null;
String funcSize = null;
InputStreamReader read = null;
BufferedReader reader = null;
counts = 0;
sizes = 0;
try {
// 添加summary
addSummary(fileName, xmlPath);
// 添加detail
addElement(fileName, null, null, xmlPath);

read = new InputStreamReader(new FileInputStream(file), "GBK");
reader = new BufferedReader(read);
String line = null;
while ((line = reader.readLine()) != null) {
if ("".equals(line)) {
continue;
}
counts++;
func = line.split(" ");
funcName = null;
funcSize = null;
for (String str : func) {
if (str.length() != 0) {
if (funcName == null) {
funcName = str;
} else {
funcSize = str;
break;
}
}
}
if (funcSize == null) {
funcSize = "0";
}
sizes += Integer.parseInt(funcSize);
// 添加func
addElement(fileName, funcName, funcSize, xmlPath);
}
// 修改count
editCount("//summary/module[@name='" + fileName + "']/count", null,
counts, xmlPath);
editCount("//summary/module[@name='" + fileName + "']/size", null,
sizes, xmlPath);
editCount("//detail/module[@name='" + fileName + "']", "count",
counts, xmlPath);
editCount("//detail/module[@name='" + fileName + "']", "size",
sizes, xmlPath);
reader.close();
read.close();
} catch (Exception e) {
e.printStackTrace();
try {
reader.close();
read.close();
} catch (IOException e1) {
}
}

}
6 楼 lk617238688 2011-01-25  
/**
* 添加Summary
*
* @param moduleName
* @param countTotal
* @throws IOException
* @throws JDOMException
*/
private static void addSummary(String moduleName, String xmlPath)
throws JDOMException, IOException {

SAXBuilder build = new SAXBuilder();
// 获得文档对象
Document doc = build.build(xmlPath);

XPath xpath = XPath.newInstance("//summary");
List list = xpath.selectNodes(doc);

Element summary = (Element) list.get(0);
Element module = new Element("module");

module.setAttribute("name", moduleName);
Element count = new Element("count");
count.setText(counts.toString());
Element size = new Element("size");
size.setText(sizes.toString());

module.addContent(count);
module.addContent(size);
summary.addContent(module);

// 文件处理
output(doc, xmlPath);

}

/**
* 修改counts、sizes
* @param Xpath
* @param attribute
* @param total
* @param xmlPath
* @throws FileNotFoundException
* @throws IOException
* @throws JDOMException
*/
private static void editCount(String Xpath, String attribute,
Integer total, String xmlPath) throws FileNotFoundException,
IOException, JDOMException {

SAXBuilder build = new SAXBuilder();
// 获得文档对象
Document doc = build.build(xmlPath);
// 获得根节点
Element element = null;
// 添加子元素func
XPath xpath = XPath.newInstance(Xpath);
List list = xpath.selectNodes(doc);
if (list.size() == 1) {
element = (Element) list.get(0);
if (Xpath.contains("summary")) {
element.setText(total.toString());
} else {
element.setAttribute(attribute, total.toString());
}
}
// 文件处理
output(doc, xmlPath);
}
5 楼 lk617238688 2011-01-25  
/**
* 文件处理
*
* @param doc
* @throws IOException
* @throws FileNotFoundException
*/
private static void output(Document doc, String xmlPath)
throws FileNotFoundException, IOException {
// 格式化并输出
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(doc, new FileOutputStream(xmlPath));
}

/**
* 添加detail
*
* @param line
* @throws IOException
* @throws JDOMException
*/
public static void addElement(String moduleName, String funcName,
String funcSize, String xmlPath) throws JDOMException, IOException {
SAXBuilder build = new SAXBuilder();
// 获得文档对象
Document doc = build.build(xmlPath);
XPath xpdetail = XPath.newInstance("//detail");
List listDetail = xpdetail.selectNodes(doc);
Element detail = (Element) listDetail.get(0);
Element module = null;
if (funcName == null) {
// 添加父元素 module
module = new Element("module");
module.setAttribute("name", moduleName);
module.setAttribute("count", counts.toString());
module.setAttribute("size", sizes.toString());
detail.addContent(module);
} else {
// 添加子元素func
XPath xpmodule = XPath.newInstance("//detail/module[@name='"
+ moduleName + "']");
List list = xpmodule.selectNodes(doc);
if (list.size() == 1) {
module = (Element) list.get(0);

Element func = new Element("func");
func.setAttribute("name", funcName);
func.setAttribute("size", funcSize);
module.addContent(func);
}
}
// 文件处理
output(doc, xmlPath);
}
4 楼 lk617238688 2011-01-25  
public class TxtFmtXml {
// 模块包含的函数个数
private static Integer counts = 0;
// 模块所包含函数的大小
private static Integer sizes = 0;

/**
* 创建XML
*
* @throws FileNotFoundException
* @throws IOException
*/
public static void bulidXmlDoc(String xmlPath)
throws FileNotFoundException, IOException {
// 创建根节点
Element root = new Element("root");
Element elementSummary = new Element("summary");
Element elementDetail = new Element("detail");

root.addContent(elementSummary);
root.addContent(elementDetail);
// 根节点添加到文档中
Document doc = new Document(root);

// 文件处理
output(doc, xmlPath);
}
3 楼 lk617238688 2011-01-25  
package com.huawei.txtfmtxml;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
/**
*
*请提供jaxen.jar(XPath要用到)、jdom.jar
**/
2 楼 lk617238688 2011-01-25  
1 楼 lk617238688 2011-01-14  
把jar包复制到另一路径下再运行,看行不行?

相关推荐

Global site tag (gtag.js) - Google Analytics