Java程序如何正确打包并正常运行在Linux系统中
来源:互联网 发布:李世石人工智能围棋 编辑:程序博客网 时间:2024/06/06 14:11
问题:该程序本地运行正常,服务端运行报错找不到第三方包中的类
原因:本地打jar包时有错,未能正确引入第三方包
解决:本地通过fat jar插件来打包,方法如下
在Eclipse 下 java 应用程序打包 Mainfest.mf 格式
首先保证程序在Eclipse下的正常执行,然后方法如下:( 写在最前面 做好的Eclipse打包 还是使用插件 Fat jar)
下载地址 :http://sourceforge.net/project/showfiles.php?group_id=115990&package_id=125924
使用说明:
Fat Jar Eclipse Plug-In Tutorial
Create a new Java Project named "demolib".
Add the Class "demolib.DemoLib.Java" containing the following code:
package demolib;
public class DemoLib {
public static void sayHello() {
System.out.println("Hello");
}
}
The Project should look something like this:
In the "Package-Explorer" (not the "Resource-View") right click on the project "demolib".
Select "+ Build Fat Jar".
A Configuration Dialog appears. Just press "Finish".
The File "demolib_fat.jar" has been created in the project root directory.
Create a new Java Project named "demorun".
In the project properties add the Library "demolib/demolib_fat.jar" to the Java Build Path":
Add the Class "demorun.DemoRunMain.java" containing the following code:
package demorun;
import demolib.DemoLib;
public class DemoRunMain {
public static void main(String[] args) {
DemoLib.sayHello();
}
}
The Project should look something like this:
Start the Export Wizard from the File-Menu ("File" -> "Export").
Select "+ Fat Jar Exporter" and click "next >".
Select the project "demorun" and click "next >".
A Configuration-Dialog appears showing the current Settings.
The Main Class - the one containing the static methode main - must be defined in the jar.
Click on the "Browse..." Button on the right side behind the Main-Class Edit field.
Select "DemoRunMain" and click the "OK" Button.
The FullyQualifiedName "demorun.DemoRunMain" is now set for "Main-Class".
Save the current Settings by clicking on the "Finish" Button.
In addition the file ".fatjar" storing the configuration settings has been created in the project root directory
The created jar file contains all classes from all referenced jar files (demolib_fat.jar) and the project classes.
This file can be executed anywhere, no classpath has to be set, because all necessary libraries
are extracted inside the "Fat Jar":
> java -jar demorun_fat.jar
Hello
- Java程序如何正确打包并正常运行在Linux系统中
- 在windows系统中如何将java程序打包,并直接运行
- 如何在虚拟机中linux系统用gcc编译并运行第一个C++程序
- 在eclipse中可以正常运行,但是打包之后就无法通过java运行了
- 程序在eclipse运行正常,但是打包上传到服务器上却报“java.lang.reflection.invocationTargetException”
- 如何在 Linux 中运行 DOS 程序!
- Java程序打包成jar包在Linux上运行
- 如何在dos中运行java程序
- 如何在命令行中运行java程序
- java程序在Eclipse打包成jar程序并在机器中用bat运行
- 打包并运行程序
- linux在sh中运行java程序
- 在ubuntu中配置java环境并运行java程序
- 解决程序在win7/vista系统中无法正常运行的问题
- linux可执行程序如何在系统后台运行
- 如何在doc下运行java程序及打包成.jar格式的Java程序
- 在自己的java代码中编译并运行程序
- Linux:如何在Linux中运行Windows程序
- go-restful 简单学习
- [斐波那契 数学技巧] 洛谷 P1306 斐波那契公约数
- UVA-112 Tree Summing
- linux 下python CGIHTTPServer 报错
- 教你彻底解决Eclipse自动补全变量名的问题
- Java程序如何正确打包并正常运行在Linux系统中
- oracle instance client imp emp
- 【深度学习】笔记7:如何将mean,binaryproto格式的均值文件转化为mean.npy格式的均值文件
- Caffe源码阅读笔记(1):Blob
- Linux C 数据库编程
- 机器学习&数据挖掘:特征选择之Filter : Focus Approach
- jQuery实现遮罩层
- mysql truncate,drop,delete的区别
- mysql中的权限