In order to create a .jar file, you need to use jar instead of java:
jar cf myJar.jar myClass.class
Additionally, if you want to make it executable, you need to indicate an entry point (i.e., a class with public static void main(String[] args)) for your application. This is usually accomplished by creating a manifest file that contains the Main-Class header (e.g., Main-Class: myClass).
However, as Mark Peters pointed out, with JDK 6, you can use the e option to define the entry point:
jar cfe myJar.jar myClass myClass.class
Finally, you can execute it:
java -jar myJar.jar
See also
- Creating a JAR File
- Setting an Application's Entry Point with the JAR Tool
In order to create a .jar file, you need to use jar instead of java:
jar cf myJar.jar myClass.class
Additionally, if you want to make it executable, you need to indicate an entry point (i.e., a class with public static void main(String[] args)) for your application. This is usually accomplished by creating a manifest file that contains the Main-Class header (e.g., Main-Class: myClass).
However, as Mark Peters pointed out, with JDK 6, you can use the e option to define the entry point:
jar cfe myJar.jar myClass myClass.class
Finally, you can execute it:
java -jar myJar.jar
See also
- Creating a JAR File
- Setting an Application's Entry Point with the JAR Tool
Sine you've mentioned you're using Eclipse... Eclipse can create the JARs for you, so long as you've run each class that has a main once. Right-click the project and click Export, then select "Runnable JAR file" under the Java folder. Select the class name in the launch configuration, choose a place to save the jar, and make a decision how to handle libraries if necessary. Click finish, wipe hands on pants.
Cannot Open .jar files
Can someone give me a tutorial on how to open .JAR files?
How to make a .jar file
How to run jar files using powershell
Should be a few ways to go about it...
# Directly invoke it
java -jar gerrit-2.15.4.war init –-batch -–no-auto-start -d gerrit_slave
# Using &
& java "-jar gerrit-2.15.4.war init –-batch -–no-auto-start -d gerrit_slave"
# Using Start-Process
Start-Process -FilePath java.exe -NoNewWindow -Wait -ArgumentList @(
"-jar gerrit-2.15.4.war"
"init"
"–-batch"
"-–no-auto-start"
"-d gerrit_slave"
) More on reddit.com Videos
Hi
Welcome to Microsoft community.
I understand you're facing issues with opening .jar files on your Windows 11 system, even after using the Jarfix tool. Let's try some additional troubleshooting steps to resolve the problem:
- Reinstall Java: First, ensure that you have Java installed on your system. If it is already installed, try reinstalling it to ensure that all necessary components are properly configured. You can download the latest version of Java from the official Java website (java.com).
- Check File Associations: Confirm that the .jar file extension is associated with Java. To do this, right-click on a .jar file, select "Open With," and choose "Choose another app." From the list, select Java (or browse to the Java executable file) and check the box that says "Always use this app to open .jar files." This will ensure that .jar files are opened with Java by default.
- Command Line: Try running the .jar file from the command line. Open the Command Prompt or PowerShell, navigate to the directory where the .jar file is located, and use the command "java -jar filename.jar" (replace "filename.jar" with the actual name of the .jar file). This will attempt to execute the .jar file using the Java runtime environment.
- Check Java Version: Make sure that you have the latest version of Java installed on your system. Older versions may not be fully compatible with Windows 11. Visit the official Java website to download and install the latest version.
- Update Windows: Ensure that your Windows 11 system is up to date with the latest updates. Sometimes, system updates can resolve compatibility issues that may be causing problems with .jar files.
If none of these steps resolve the issue, it might be helpful to provide more details about the specific error messages or behaviors you encounter when trying to open .jar files. Additionally, you could consider seeking assistance from the Java community or contacting the support team for the application or program associated with the .jar file you're trying to open.
Best regards
Derrick Qian | Microsoft Community Support Specialist
same, but I was using windows 10.