In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to create and execute Jar files under Linux", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to create and execute Jar files under Linux" article.
How to create a JAR file in Linux
1. First, write a simple Java class with the main method for demonstration purposes for an application called HowtoingApp.
$vim HowtoingApp.java
Copy and paste the following code into the HowtoingApp.java file.
Public class HowtoingApp {public static void main (String [] args) {System.out.println ("Just executed HowtoingApp!");}}
Save the file and close it.
two。 Next, we need to compile and package the class into a JAR file using the javac and jar utilities, as shown in the figure.
$javac-d. HowtoingApp.java$ ls$ jar cvf howtoingapp.jar HowtoingApp.class$ ls
3. After creating the howtoingapp.jar, you can now execute the file using the java command, as shown in the figure.
$java-jar howtoingapp.jarno main manifest attribute, in howtoingapp.jar
From the output of the above command, we encountered an error. JVM (Java virtual machine) could not find our main manifest property, so the main class containing the main method (public static void main (String [] args)) could not be found.
The JAR file should have a listing containing a line * *: classname** in the form of Main-Class that defines a class with a main method that serves as the starting point for the application.
4. To resolve the above errors, we need to update the JAR file to include the manifest properties and code. Let's create a MANIFEST.MF file.
$vim MANIFEST.MF
Copy and paste the following line into the MANIFEST.MF file.
Main-Class: HowtoingApp
Save the file, and then use the following command to add the file MANIFEST.MF to howtoingapp.jar.
$jar cvmf MANIFEST.MF howtoingapp.jar HowtoingApp.class
5. Finally, when we execute the JAR file again, it should produce the expected results, as shown in the output.
$java-jar howtoingapp.jarJust executed HowtoingApp!
For more information, see the java, javac, and jar command man pages.
The above $man java$ man javac$ man jar is about the content of this article on "how to create and execute Jar files under Linux". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.