Reputation: 2562
I am starting web development with JSP, and I have been working on my application or a while. I have a custom logging class, which is in my personal library. I don't want to export the library to a jar
file every time I make a change, so I have added my Eclipse library to the build path by right clicking on my web app, going to Build Path --> Projects --> Add --> (library name)
.
Eclipse does not pick up an error when I import it into my Java classes. Although, I call a method from one of my application's classes, (which has imported my custom logging class), and it throws a ClassNotFoundException
.
I have looked online, and (correct me if I'm wrong) it looks like the way to solve this is to export my library to a jar
file and put it under the /(project)/WebContent/WEB-INF/lib
folder, and then put it into the build path.
I do not want to do this, as I make many changes to my library, very frequently. So how can I get Tomcat to recognize that my library is in the build path without exporting it?
Thanks in advance.
Upvotes: 1
Views: 427
Reputation: 30088
I usually try not to respond to a question with a suggestion that you do things completely differently, but in this case, I think it's warranted.
So, first..logging is a "solved problem". It is exactly the sort of wheel that most people shouldn't re-invent. Take a log at LogBack and SLF4J. The most that you should have to do, if you have some really extremely unique situation, is to implement a new Appender.
Now, to the more general question. A suggestion that I often make to struggling developers is remove their project's dependence on any particular IDE. You'll have a much easier time of things if your project is configured so that it can be built, debugged, and packaged from the command line. You can then continue to use your IDE - just don't make your project dependent on it.
There are a number of ways to do this, but a popular one that works fairly well, and integrates with Eclipse and many other IDEs, is Maven.
If both your utility library and your project that depends on it are built with Maven, then you can simply declare (in you project's Maven configuration) that it is dependent on your utility library.
Then you can simply do 'mvn install' in your utility library's project, and your dependent project will pick up the change.
Once you have all of that working, you can import the Maven projects into Eclipse, and it will all work there as well.
Upvotes: 2