I'm trying to make a jar file out of two classes, one of which depends on an external jar. I have a directory with a manifest.txt, a lib folder containing the external jar RXTXcomm.jar, and a folder named Arduino containing my two classes, SendValue.java and SerialClass.java.
First I'm compiling my classes using:
javac arduino\*.java
This creates 3 new files, SerialClass$1.class, SerialClass.class and SendValue.class. To make the jar file, I'm running:
jar -cfm send.jar manifest.txt arduino\*.class lib\rxtxcomm.jar
This works fine. I then try to run the file using:
java send.jar
I get the error:
Could not find or load main class send.jar
I've also tried to run it with the following command, and got the same error:
java -cp . send.jar
The only line in my manifest.txt is :
Main-Class: Arduino.SendValue
My classes run fine in Eclipse, so I'm assuming they're not the problem. SendValue.java has the line:
public static void main(String[] ag) {
as it's supposed to.
Any ideas?
You want to run your jar
using:
java -jar send.jar
Also, unless you want to do some magic with nested jars with some tool like OneJar , you should remove lib\\rxtxcomm.jar
from your jar
command, and add the following line to your manifest.
Class-Path: lib\rxtxcomm.jar .
If you're going to use the command line or terminal for running a single java executable, then use
java -jar send.jar
Also it would be better if you went through compiling and testing using an IDE such as Netbeans, IntelliJ IDEA, or Eclipse as they're meant to do such stuff and are more reliable on doing the steps unlike the human brain.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.