

Launch Configuration identifies which program should be exported.įind the one that runs the class containing your main() method.Įxport Destination is the name and location of the JAR file you want to generate. In Eclipse, select File → Export, then Java → Runnable JAR File.
#Java jar file run code
Read more on Working with JAR and Manifest files In JavaĪccumulo,1,ActiveMQ,2,Adsense,1,API,37,ArrayList,17,Arrays,16,Bean Creation,3,Bean Scopes,1,BiConsumer,1,Blogger Tips,1,Books,1,C Programming,1,Collection,5,Collections,29,Collector,1,Command Line,1,Compile Errors,1,Configurations,7,Constants,1,Control Statements,8,Conversions,6,Core Java,93,Corona India,1,Create,2,CSS,1,Date,3,Date Time API,35,Dictionary,1,Difference,1,Download,1,Eclipse,2,Efficiently,1,Error,1,Errors,1,Exception,1,Exceptions,3,Fast,1,Files,14,Float,1,Font,1,Form,1,Freshers,1,Function,3,Functional Interface,2,Garbage Collector,1,Generics,4,Git,4,Grant,1,Grep,1,HashMap,1,HomeBrew,2,HTML,2,HttpClient,2,Immutable,1,Installation,1,Interview Questions,5,Iterate,2,Jackson API,3,Java,30,Java 10,1,Java 11,5,Java 12,5,Java 13,2,Java 14,2,Java 8,111,Java 8 Difference,2,Java 8 Stream Conversions,2,java 8 Stream Examples,3,Java 9,1,Java Conversions,11,Java Design Patterns,1,Java Files,1,Java Program,3,Java Programs,105,Java Spark,1,java.lang,5, can also export your program as a “runnable JAR file” that contains all the code in a single file. Main-Class: com/mycomp/myproj/dir1/MainClass1 We can add our java file to manifest file so that we no need to pass the class name to java command while running it from command line.Įxample with custom class in Manifest.mf file : Implementation-Vendor: Oracle Corporation Implementation-Title: Java Runtime Environment Specification-Title: Java Platform API Specification Here, is what a default manifest file looks likeīelow is from official java version jrt-fs.jar from java 11. Although the default manifest file contains just two entries, but complex manifest files can have way more. Default manifest file is named as MANIFEST.MF and is present in the META-INF sub-directory of archive. Each JAR file have a manifest file by default. MANIFEST.MF file: Each JAR file contains a manifest file that describe the features of the archive. Java -cp myJavaJar.jar 2.MainClass2 /home/myhome/datasource.properties /home/myhome/input.txt Then : Just need to pass the complete fully classified name of the class. You can create your jar without Main-Class in its Manifest file. Solution: The solution for this issue is described below. (In the above command, '/home/myhome/datasource.properties' and '/home/myhome/input.txt' are the command line arguments). Jar cfe myJavaJar.jar 2.MainClass2 com/mycomp/myproj/dir2/MainClass2.class /home/myhome/datasource.properties /home/myhome/input.txtĬom/mycomp/myproj/dir2/MainClass2.class : no such file or directory But is there any way by which I can specify some argument on command line to run whichever class I wish to run? I know that I can specify one class as main in my Manifest file. It has directory structure for the main classes as follows: I am trying to run it from command-line on Linux box. I want to be able to run each one of those as per the need. I have a JAR with 4 classes, each one has Main method.
#Java jar file run how to
How to run a class from Jar which is not the Main-Class in manifest file:

Here, flag cp is to set the jar in the java class-path.
