IDEA將Maven項(xiàng)目中指定文件夾下的xml等文件編譯進(jìn)classes的方法
出處:https://www.cnblogs.com/SunSpring
eclipse下面創(chuàng)建的Maven項(xiàng)目,使用mybatis。eclipse里面能正常啟動(dòng),在idea中一直卡在maybatis 加載位置。
1、首先是不報(bào)錯(cuò)也沒反應(yīng)。這個(gè)時(shí)候需要我們重寫SqlSessionFactoryBean 讓錯(cuò)誤顯示出來。public class BeanFactory extends SqlSessionFactoryBean { @Override protected SqlSessionFactory buildSqlSessionFactory() throws IOException { try { return super.buildSqlSessionFactory(); } catch (NestedIOException e) { e.printStackTrace(); throw new NestedIOException('Failed to parse mapping resource:', e.getCause()); } }}2、修改applicationContext.xml 中的mybatis配置。
<bean class='com.util.BeanFactory'> <property name='dataSource' ref='dataSource'></property> <property name='configLocation' value='classpath:mybatis-config.xml' /> </bean>
這樣就能打印出mybatis加載過程的錯(cuò)誤。
重新啟動(dòng)項(xiàng)目調(diào)試,報(bào)錯(cuò)提示找不到mybatis-config.xml 中配置的**mapper.xml文件。打開編譯的target文件找到對(duì)應(yīng)的mapper.xml目錄發(fā)現(xiàn)果然沒有xml文件,我們知道m(xù)aven項(xiàng)目的標(biāo)準(zhǔn)項(xiàng)目結(jié)構(gòu)如下:
(1)src/main/java:存放主代碼
(2)src/main/resources:存放項(xiàng)目的資源文件,如:Spring 的核心配置文件
(3)src/test/java:存放測(cè)試代碼
(4)src/test/resources:存放測(cè)試的資源文件
(5)target:目標(biāo)文件輸出位置,如:編譯后的 .class 文件
(6)pom.xml:Maven 項(xiàng)目的核心配置文件
(7)src/main/webapp :它是 Web 項(xiàng)目的主目錄,用于存放 .jsp、.js、.css 等文件
我們習(xí)慣把mybatis的mapper.xml文件Mapper.java放一起,都在src/main/java下面,這樣maven打包時(shí),如果沒有設(shè)置為資源文件則maven不會(huì)打包,maven認(rèn)為src/main/java只是java的源代碼路徑。可以看到idea里面Modules,只有src/test/resources是ResourceFolders。
解決辦法:修改pom.xml,還有其他方法自己可以看下。
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build>
然后再重新編譯項(xiàng)目就行了。
特別提醒:idea有時(shí)候修改了pom.xml文件沒有重新加載,重新編譯項(xiàng)目的時(shí)候還是不行。這個(gè)時(shí)候我們要再maven那里點(diǎn)擊下“Reimport” 按鈕,重新加載下。
我就是這個(gè)原因搞了很久都沒找到問題。
以上就是IDEA將Maven項(xiàng)目中指定文件夾下的xml等文件編譯進(jìn)classes的方法的詳細(xì)內(nèi)容,更多關(guān)于IDEA 將xml編譯進(jìn)classes的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. PHP設(shè)計(jì)模式中工廠模式深入詳解2. PHP循環(huán)與分支知識(shí)點(diǎn)梳理3. xpath簡(jiǎn)介_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理4. 詳細(xì)分析css float 屬性以及position:absolute 的區(qū)別5. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)6. 得到XML文檔大小的方法7. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))8. ASP中格式化時(shí)間短日期補(bǔ)0變兩位長(zhǎng)日期的方法9. ASP實(shí)現(xiàn)加法驗(yàn)證碼10. ASP基礎(chǔ)知識(shí)Command對(duì)象講解
