java项目怎么打成可运行的jar包

2024-05-07 09:58

本文主要是介绍java项目怎么打成可运行的jar包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

java项目怎么打成可运行的jar包

Myeclipse java 导出 运行 jar包 
测试环境: MyEclipse  V8.6
java项目打jar包分为2种情况:
建议选择第二种(简单)
一、java项目没有导入第三方jar包
这时候打包就比较简单:
1. 首先在MyEclipse中打开项目, 右键点击项目,选择“Export”;
2. 选择Java/JAR file,Next;
3. Select the resources to export中可以选择你想要包含的项目文件夹,一些不必要的文件夹就无需放进去了,免得增大空间;
这里有几个选项:
    * Export generated class files and resources 表示只导出生成的.class文件和其他资源文件
    * Export all output folders for checked projects 表示导出选中项目的所有文件夹
    * Export java source file and resouces 表示导出的jar包中将包含你的源代码*.java,如果你不想泄漏源代码,那么就不要选这项了
    * Export refactorings for checked projects 把一些重构的信息文件也包含进去
在Select the export destination中选择导出的jar的路径,Next.
4. 下一页可以选择是否导出那些含有警告warning或者错误errors的*.class文件。一般不用理他,Next
5. 下一个页面里可以对项目做一些配置。(如果项目没有引入第三方jar包,这项我们采用系统默认的选项就OK,Main class一定要设置成为你项目的那个主方法入口类)
    * Generate the manifest file是系统帮我们自动生成MANIFEST.MF文件,如果你的项目没有引用其他class-path,那可以选择这一项。
    * Use existing mainfest from workspace。这是可以选择我们自定义的.MF文件,格式如上所写。
    * Seal content。要封装整个jar或者指定的包packet
    * Main class。这里可以选择你的程序入口,将来打包出来的jar就是你这个入口类的执行结果。
最后Finish,搞定。 ......
二、java项目有导入第三方Jar包
1,右击项目,单击export=》java=》选第三个,Runnable Jar file (可执行的jar文件),Next,
2,选择launch configuration(程序入口配置),Exportdestination(导出目标)
Library handing:   选择第一个 引用的jar包会整合到项目中去。
                    选择第二个 引用的jar包会单独放在项目根目录下(推荐)。
                    选择第三个 引用的jar包会单独放在一个文件夹下,这个文件夹和导出的jar放在同一目录下,
finish。


遇到的问题:
(网络来源)为什么export-->runnable jar file的launch configuration没有东西可以选择?对于这个问题,网上答案少之又少,我来制造些内容吧。
为什么MyEclipse8.5的export-->runnable jar file-->的launch configuration里面没有可以选择的东西了,其实是要把你要打包成jar文件的工程的main方法运行一次,比如main方法在A类里,运行一次A就有了
   我是看见下面这段,试了一下弄出来的,喜欢的人仔细研究一下  Creating a Java application launch configuration
When you choose Run >Run As >Java Application to launch your class, you are running your class using a generic Java Application launch configuration that derives most of the launch parameters from your Java project and your workbench preferences.  In some cases, you will want to override the derived parameters or specify additional arguments.
You do this by creating your own Java Application launch configuration.
Select or from the workbench menu bar.  This opens a dialog that lets you create, modify, and delete launch configurations of different types.
Select Java Application in the left hand list of launch configuration types, and press the New button in the toolbar. This will create a new launch configuration for a Java application. The tabs on the right hand side allow you control specific aspects of the launch.
The Main tab defines the class to be launched. Enter the name of the project containing the class to launch in the project field, and the fully qualified name of the main class in the Main class field. Check the Stop in main checkbox if you want the program to stop in the main method whenever the program is launched in debug mode.
Note:  You do not have to specify a project, but doing so allows a default classpath, source lookup path, and JRE to be chosen.
The Arguments tab defines the arguments to be passed to the application and to the virtual machine (if any). You can also specify the working directory to be used by the launched application.
The JRE tab defines the JRE used to run or debug the application. You can select a JRE from the already defined JREs, or define a new JRE.
The Classpath tab defines the location of class files used when running or debugging an application. By default, the user and bootstrap class locations are derived from the associated project's build path. You may override these settings here.
The Source tab defines the location of source files used to display source when debugging a Java application. By default, these settings are derived from the associated project's build path. You may override these settings here.
The Environment tab defines the environment variable values to use when running or debugging a Java application. By default, the environment is inherited from the Eclipse runtime. You may override or append to the inherited environment.
The Common tab defines general information about the launch configuration.  You may choose to store the launch configuration in a specific file and specify which perspectives become active when the launch configuration is launched.

这篇关于java项目怎么打成可运行的jar包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/967026

相关文章

Android 12解决push framework.jar无法开机的方法小结

《Android12解决pushframework.jar无法开机的方法小结》:本文主要介绍在Android12中解决pushframework.jar无法开机的方法,包括编译指令、框架层和s... 目录1. android 编译指令1.1 framework层的编译指令1.2 替换framework.ja

SpringBoot中四种AOP实战应用场景及代码实现

《SpringBoot中四种AOP实战应用场景及代码实现》面向切面编程(AOP)是Spring框架的核心功能之一,它通过预编译和运行期动态代理实现程序功能的统一维护,在SpringBoot应用中,AO... 目录引言场景一:日志记录与性能监控业务需求实现方案使用示例扩展:MDC实现请求跟踪场景二:权限控制与

Python开发文字版随机事件游戏的项目实例

《Python开发文字版随机事件游戏的项目实例》随机事件游戏是一种通过生成不可预测的事件来增强游戏体验的类型,在这篇博文中,我们将使用Python开发一款文字版随机事件游戏,通过这个项目,读者不仅能够... 目录项目概述2.1 游戏概念2.2 游戏特色2.3 目标玩家群体技术选择与环境准备3.1 开发环境3

Java NoClassDefFoundError运行时错误分析解决

《JavaNoClassDefFoundError运行时错误分析解决》在Java开发中,NoClassDefFoundError是一种常见的运行时错误,它通常表明Java虚拟机在尝试加载一个类时未能... 目录前言一、问题分析二、报错原因三、解决思路检查类路径配置检查依赖库检查类文件调试类加载器问题四、常见

Java注解之超越Javadoc的元数据利器详解

《Java注解之超越Javadoc的元数据利器详解》本文将深入探讨Java注解的定义、类型、内置注解、自定义注解、保留策略、实际应用场景及最佳实践,无论是初学者还是资深开发者,都能通过本文了解如何利用... 目录什么是注解?注解的类型内置注编程解自定义注解注解的保留策略实际用例最佳实践总结在 Java 编程

gradle第三方Jar包依赖统一管理方式

《gradle第三方Jar包依赖统一管理方式》:本文主要介绍gradle第三方Jar包依赖统一管理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录背景实现1.顶层模块build.gradle添加依赖管理插件2.顶层模块build.gradle添加所有管理依赖包

Java 实用工具类Spring 的 AnnotationUtils详解

《Java实用工具类Spring的AnnotationUtils详解》Spring框架提供了一个强大的注解工具类org.springframework.core.annotation.Annot... 目录前言一、AnnotationUtils 的常用方法二、常见应用场景三、与 JDK 原生注解 API 的

Java controller接口出入参时间序列化转换操作方法(两种)

《Javacontroller接口出入参时间序列化转换操作方法(两种)》:本文主要介绍Javacontroller接口出入参时间序列化转换操作方法,本文给大家列举两种简单方法,感兴趣的朋友一起看... 目录方式一、使用注解方式二、统一配置场景:在controller编写的接口,在前后端交互过程中一般都会涉及

Java中的StringBuilder之如何高效构建字符串

《Java中的StringBuilder之如何高效构建字符串》本文将深入浅出地介绍StringBuilder的使用方法、性能优势以及相关字符串处理技术,结合代码示例帮助读者更好地理解和应用,希望对大家... 目录关键点什么是 StringBuilder?为什么需要 StringBuilder?如何使用 St

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格