我正在尝试提交我的Java作业,并希望创建一个包含已编译的.class文件和我的原始源代码.java文件的jar文件。我正在使用IntelliJ,但没有找到将.java导出为jar的选项。是否有通过命令行完成此操作的方法?
尝试
jar cf jar-file input-file(s)
查看 http://docs.oracle.com/javase/tutorial/deployment/jar/build.html 获取更多信息。
对于Intellij IDEA版本11.0.2
依次点击File | Project Structure | Artifacts,然后按下alt+insert或点击加号图标并创建新的artifact,选择--> jar --> From modules with dependencies。
接下来转到Build | Build artifacts --> 选择你的artifact。
- Start Command Prompt.
- Navigate to the folder that holds your class files:
C:\>cd \mywork
- Set path to include JDK’s bin. For example:
C:\mywork> path c:\Program Files\Java\jdk1.7.0_25\bin;%path%
- Compile your class(es):
C:\mywork> javac *.java
- Create a manifest file
manifest.txt with, for example, this content:
Manifest-Version: 1.0
Created-By: 1.8.0_171 (Oracle Corporation) #your jdk version
Main-Class: mainPackage.MainClass
- Create the jar file:
C:\mywork> jar cvfm Craps.jar manifest.txt *.class
Ant 脚本
来满足您的需求。"Java development user guide" ==> "Tasks" ==> "Creating JAR files."
,按照"Creating a new JAR file"或"Creating a new runnable JAR file"的说明进行操作。