The pit of eclipse packaging maven project

1. Question:

  The company has developed a project that needs to be run as a background service. The composition of the entire project is: [maven + spring + eclipse]

  There are many problems encountered when using packaging:

  (1) Integration of maven tools in eclipse [ configuration warehouse ]

  (2) The packaged jre environment must be provided by the jdk itself, and the java operating environment must be configured in [performance--java] [multiple environment exceptions will be reported]

  (3) The command to package the maven project can use [install/maven build] install will put the installation package into the warehouse, and build will bring the installation package to [target]

  (4) [spring-ApplicationContext] If you use spring's manual loading, it will report [offending resource] when reading the configuration file.

  (5) If the dependency of maven depends on other local jar packages in addition to the warehouse itself, you need to install the local jar package in Xi'an to the local warehouse and then package it in order to enter

 

2. Solution:

  (1) If the configuration file cannot be obtained by manually loading the spring container, [classpath + *]

    public static void init() {
        if (ac == null) {
            //ac = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");//修改为添加*号即可
            ac = new ClassPathXmlApplicationContext("classpath*:applicationContext-dao.xml");
            resource = new ClassPathResource("/properties/file.properties");
        }
    }

  

3. Summary:

  (1) Why add the [ * ] sign to identify the classpath problem. According to the information on the Internet, the configuration files of other jar package projects can be identified after adding an asterisk. If you have no in-depth understanding, please comment if you know it.

The difference between classpath and classpaht*, classpath* will search all files in the root directory until it finds a matching file. The classpath will only look in /WEB-INF/classes.

  (2) When debugging the service, I thought of a question. After [cmd] starts a jar package, the console can see the debugging output of the program at that time. How to open the console again to view the output of this program?

      I tried the jobs command of linux, but when the console running at that time was closed, the job was also closed, and I could not re-output to this console

  (3) There is also a solution to the error in the spring container loading configuration file:

<plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-shade-plugin</artifactId>  
                <executions>  
                    <execution>  
                        <phase>package</phase>  
                        <goals>  
                            <goal>shade</goal>  
                        </goals>  
                        <configuration>  
                            <finalName>dwbi-excel</ finalName >   
                            < shadedArtifactAttached > true </ shadedArtifactAttached >   
                            < shadedClassifierName > jar-with-dependencies </ shadedClassifierName >  
                <!-- The following is another solution to the problem that the configuration file cannot be loaded, I did not test it, it was tested by a colleague --> < transformers > < transformer implementation ="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" > < mainClass > ${mainClass} </ mainClass > </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.tooling</resource> </transformer> </transformers> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin>

 

      

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325229935&siteId=291194637