1

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.

asgs
  • 3,928
  • 6
  • 39
  • 54
mattbdean
  • 2,532
  • 5
  • 26
  • 58
  • why don't you want that library to be packaged into a JAR? also, how are you adding this library to the Build Path? – asgs Sep 22 '12 at 01:19
  • As I said in my question, I make frequent changes to my library. I don't want to export it every time I make a change, and for your second question, (which I have also said in my question) I am right clicking on my web app, going to `Build Path --> Projects --> Add --> (library name)`. – mattbdean Sep 22 '12 at 01:23

1 Answers1

2

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.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • Thank you! I will defiantly look into Maven for my future projects. Also, for the logging class, I built that for fun and was testing it out :) – mattbdean Sep 22 '12 at 01:35
  • I applaud your idea of 'fun'. I suggest, however, that you don't use your custom logger in a production application :-) – GreyBeardedGeek Sep 22 '12 at 01:38
  • Okay, I'll switch over to Java's logging class. – mattbdean Sep 22 '12 at 01:50
  • Seriously - look at SLF4J / LogBack - java.util.logging is probably the last thing that you want to use (your own implementation might actually be better). – GreyBeardedGeek Sep 22 '12 at 02:01
  • this does not even begin to answer the question. and... do you prefer being dependent on maven rather than an IDE? – Mo'in Creemers Nov 02 '12 at 20:01
  • @moin - yes, I'd prefer to be dependent on Maven instead of a particular IDE - that's exactly the point. It gives you a repeatable build that can be invoked from a script (as in a continuous build tool like Jenkins or Hudson), and lets you use any IDE that you want - most Java IDEs have Maven support. Or you can do exactly the same thing with Ant, or Gradle, or several other build tools. This isn't that important if your project is for your consumption only, but as soon as you have more than one person working on a project (open source, or corporate environment), this becomes very important. – GreyBeardedGeek Nov 03 '12 at 14:38