This essay is mainly written to start the jar, if you need to rely on the other jar package what to do, I will take the RabbitMQ customer service boot as an example.
PackageCOM.ROCKCODE.WWW.RABBITMQ;Importjava.io.IOException;Importjava.util.concurrent.TimeoutException;ImportCom.rabbitmq.client.AMQP;ImportCom.rabbitmq.client.Channel;Importcom.rabbitmq.client.Connection;Importcom.rabbitmq.client.ConnectionFactory;ImportCom.rabbitmq.client.DefaultConsumer;ImportCom.rabbitmq.client.Envelope; Public classConsumer {Private Final StaticString queue_name = "Rock"; Public Static voidMain (string[] args) {ConnectionFactory factory=NewConnectionFactory (); Factory.setusername ("Guest"); Factory.setpassword ("Guest"); Factory.sethost ("LocalHost"); Connection Conn; Try{conn=factory.newconnection (); Channel Channel=Conn.createchannel (); Channel.queuedeclare (Queue_name,false,false,false,NULL); System.out.println ("[*] waiting for messages. To exit Press CTRL + C "); Com.rabbitmq.client.Consumer Con=NewDefaultconsumer (channel) {@Override Public voidhandledelivery (String consumertag, Envelope Envelope, AMQP. Basicproperties Properties,byte[] body)throwsIOException {String message=NewString (Body, "UTF-8"); System.out.println ("[x] Received '" + Message + "'"); Try{doWork (message); } Catch(interruptedexception e) {e.printstacktrace (); } finally{System.out.println ("[X] Done"); } } }; Channel.basicconsume (Queue_name,true, con); } Catch(IOException e) {}Catch(TimeoutException e) {}}Private Static voidDoWork (String Task)throwsinterruptedexception { for(CharCh:task.toCharArray ()) { if(ch = = '. ') Thread.Sleep (1000); } }}
Customer service end depends on Amqp-client-5.0.0.jar and Slf4j-api-1.7.25.jar, first look at MANIFEST. MF file
And look at the directory structure.
The following are the jar files Amqp-client-5.0.0.jar and slf4j-api-1.7.25.jar that are dependent on LIB.
We are opening CMD, set the path set cp= first. Lib/amqp-client-5.0.0.jar;lib/slf4j-api-1.7.25.jar: JAVA-CP%cp%-jar Consumer.jar
[x] Received ' Hello. '
[x] Done
Yes, I got the message. But there is an error, Failed to load Class "Org.slf4j.impl.StaticLoggerBinder".
We will Slf4j-nop-1.7.21.jar join the Lib directory, reset the path, set cp=.; Lib/amqp-client-5.0.0.jar;lib/slf4j-api-1.7.25.jar;lib/slf4j-nop-1.7.21.jar;
Modify the MANIFEST at the same time. MF file
Try again java-cp%cp%-jar Consumer.jar
That's fine.
Next I will be producer and consumer separately packaged into jars, through the command line and script to execute, thank you, hope to help!
"Javac, Java, Jar command", article three