Maven hits Jar pack, executes various problems with the jar with Doc command (record Memo)

Source: Internet
Author: User
Tags pack

Event causes:

The company has a business needs, two systems docking, the two sides of the intermediary library to carry out data exchange, set up the middle table, the other side of the use of Oracle, our use of SQL Server, I am responsible for writing a program to read data from Oracle's intermediate tables to write to the company's SQL Server, I used the Spring+mybatis+quartz+atomikos framework to complete a project that configured multiple data sources to read data from Oracle to SQL Server, and the project had no pages, and the original version was Tomcat started this program, However, due to the leadership requirements of the program does not run under Tomcat, the request to change the project to EXE type does not need any environmental installation direct click to run.

It was a bit of a mask when you first heard this demand, before how to use Java to write a desktop program, and then looked at the online data, know to want to make the project into an executable jar package, and then through the exe4j into an EXE, know how to do, I began to my MAVEN project to play jar bag, The doc command then executes the jar package for testing, which results in a variety of problems:

Question one:

After the MAVEN project hits the jar package, the Mian function portal is not specified, and spring's project is detached from Tomcat to get the instance invocation method through the context of spring.

ApplicationContext context = new Classpathxmlapplicationcontext ("Spring-mybatis.xml");
Scheduler Scheduler = (Scheduler) context.getbean ("Testschedulerfactorybean");

We're going to write a class that contains the main method to start the spring container, write it, and specify the main function entry in the MAVEN packaged plug-in, and fill in the MainClass with the class full name


Question two:

When the MAVEN project hits the jar package, it misses the XML of the mapper layer, causing the mapping of the Mapper instance to fail at startup




Here, when we pack, we're going to package the XML file completely, and we're going to add the Pom.xml




Question three: After Maven hit the jar package, the outside reference jar package didn't go in, because I introduced an externally imported Oracle and SQL Server database-driven jar package that caused Maven to package the two jar packages without the package included


Solution: Because of the haste, I took a rough approach and copied the two jar packages directly underneath the Maven packaged Lib package,



But the start of the time is still an error, said that can not find class files, here I overlooked a problem maven package will have a MANIFEST.MF file, which has a variety of configuration information, jar Start is read inside the configuration information to start,



Classpath inside to add the outside Jar Packet Road strength information, otherwise the jar started when the driver can not read, it will fail


Start Jar Pack after joining



The difficulty finally started, the MAVEN project through the jar package start task to read and write database operation is successful, the next is to use EXE4J to the jar package to the EXE, the following article will continue to introduce, now record memo, hope will be helpful to everyone.

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.