"Javac, Java, Jar command", article three

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.