1

I am using eclipse to develop and test a spring mvc application. I use Run as...Run on server frequently during development to test minor changes. I am running into a ClassNotFound error whose solution seems to involve moving a couple of jars into the tomcat 8 lib directory so that they can be available at run time. (The classes containing the jars are in the application build path in eclipse.) The problem with moving the jars to the tomcat lib folder is that the jars are also needed at compile time. When I move the jar to $CATALINA_HOME/lib, I get an error indicating that there are duplicate jars due to the jar being in my pom.xml. But if I delete it from my pom.xml, eclipse will not compile the app. How can I move a jar to $CATALINA_HOME/lib and still have eclipse compile my app?

I tried setting <scope>runtime</scope> and <scope>provided</scope> but neither of these addresses the problem. Here is what I have in my pom.xml:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>javax.mail-api</artifactId>
    <version>1.5.2</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
</dependency>  

EDIT#1:

I also tried moving the jar to the tomcat lib folder and then adding the jar to the buildpath in eclipse as an external jar so that I could delete the dependencies from pom.xml and still have eclipse compile the app. But when I do this, eclipse gives me the following error each time I try Run As..Run on Server:

Several ports (8080, 8009) required by Tomcat v8.0 Server at localhost are  
already in use. The server may already be running in another process, or a  
system process may be using the port. To start this server you will need to  
stop the other process or change the port number(s).  

Of course, I went to the tomcat bin folder and ran shutdown.sh, but that did not stop the new error.

EDIT#2

When I shut down tomcat from within eclipse by clicking on the red button, eclipse says that tomcat has been stopped. However, when I try to restart tomcat by doing Run As..Run on Server again, I get the error described in EDIT#1 above. The temporary resolution of this error comes when I completely shut down my computer and reboot. Then I am able to do Run As..Run on Server again and recreate the situation. Only now a new error is being thrown. I documented the new error in a separate posting. However, I keep getting the same problem of the error message from EDIT#1 every time I try to do successive Run As..Run on Server launches to test small changes in the code. So this current question is not resolved because putting the java mail jar in tomcat lib folder and using scope provided requires an unacceptable reboot every time I want to relaunch the app from within eclipse. shutdown.sh does not work either.

Community
  • 1
  • 1
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • Can we see the stacktrace please? – Alessandro Santini Jan 08 '15 at 00:40
  • @AlessandroSantini lemme reboot my machine and see if I can reproduce the error to get you the stack trace. – CodeMed Jan 08 '15 at 00:48
  • Knowing its eclipse, I have a feeling your machine reboot will probably resolve your problem. You should retain your maven _provided_ entries – Angad Jan 08 '15 at 00:55
  • Concerning your error described in Edit#1: you have some processes running on the port you want to run your server on. Find out which ones by executing "netstat -a -b" in a console (run as administrator) then use the task manager to kill the process which is using your port. – Chris Neve Apr 13 '16 at 12:00

2 Answers2

1
you can write lib launch file which you can run on maven install.
Inside launchConfiguration mentioned string attribute like below 
<stringAttribute key="M2_GOALS" value="clean package install"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="false"/>
<intAttribute key="M2_THREADS" value="1"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace:/Lib}"/>

This will compile all the jar file and put it into lib folder in webapp directory
Tanvi B
  • 1,577
  • 11
  • 14
  • Thank you and +1 for taking the time to share this. I cannot verify your answer because I am not currently using this technology. But if other user's verify this or the other answer, I will be happy to mark an answer as accepted. – CodeMed May 12 '16 at 18:33
0

Ok, I re-read your post and I think I have nailed it. To kill that Tomcat instance, press the red button in the Console window in Eclipse. shutdown.sh may not close it.

As per the JAR files, you need them both in the Tomcat lib directory and in the Maven dependency. If they are "provided", they will be used at compile and test time but won't be deployed (which is what you expect). You need then to copy them in the tomcat/lib directory to avoid clashes.

Alessandro Santini
  • 1,943
  • 13
  • 17