java - IntelliJ not using external Jar's if not added via Maven when running JSF application? -


i have simple line of code called .xhtml file ( in jsf 2.0 project ) looks like:

try {     class.forname("com.mysql.jdbc.driver"); }catch(exception e) {     e.printstacktrace(); } 

so in c:\ folder have file: mysql-connector-java-5.1.24-bin. have added jar extenral jar in intellij idea 12.

when start application this, "class not found exception." however, when add dependency pom.xml file:

<dependency>     <groupid>mysql</groupid>     <artifactid>mysql-connector-java</artifactid>     <version>5.1.6</version> </dependency> 

i no exception , class loaded fine.

here screenshot: enter image description here

the jar file underlined green jar added externally **file -> project structure -> libraries **

the 1 underlined red jar file downloaded maven.

my question is: why class not found exception, although have added jar externally?

in case require jar file not able download via maven, supposed do?

one information: created sample java project 1 class only, , added external jar file method explained above. no maven, no tomcat, nothing. simple main method. ran same code, , worked fine. has have intellij , 1 or more of:

  • maven
  • tomcat ( deploying war file )
  • maven , tomcat?

edit: when add external jar only , try importing class com.mysql.jdbc... intellij idea not come warnings / errors. finds class, after deployment, seems class can not found anymore.

the webapp deployed , run on tomcat. tomcat doesn't care jars in intellij source project. matters tomcat set of jar files under web-inf/lib directory of deployed webapp. jars in classpath of webapp.

i don't know how intellij builds , deploys webapps, when maven in picture. i'd guess deploys jars in compile , runtime scopes of maven project. external jar, it's possible configure intellij project in order include in built , deployed archive.

but anyway, if use maven, must able build war without using intellij. that's whole point of build tool: it's used build project without ide. necessary jars must known maven. jar, if not available in maven central, should added own local maven repo (at least), or company's private repo.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -