• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Maven executable WAR file can't find lib

 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have a maven WAR file that has a main class in it. I want to run this main class using command line similar to Hudson, which uses Jetty from behind


I have looked through Hudson's POM file and kind of understand how the file structure looks like (once WAR is exploded). I followed Hudson POM to set up my own project and when I export the WAR, this same structure looks fine.

Now the problem I'm having is that the main class need some dependencies (namely Log4J for logging and Jackson for JSON). These dependencies are in the WEB-INF/lib folder which the web app uses. How can I set up the main class to point to the WEB-INF/lib folder to get these dependencies.




The POM <build> section configures what the main class is and its dependencies (shown below).

Given what I have done or configured, when I run it, it gives NoClassDefFoundError, clearly it can't find the lib


How can I solve this?

POM file



 
Saloon Keeper
Posts: 12154
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, it doesn't really make sense to have a main class in a WAR. A WAR packages a web application, not a desktop application.

Do you want to create a desktop or a web application? Does it need to integrate with Hudson? If it is a desktop application, then why does it need Jetty?

Note that dependencies go inside the <dependencies> element, not the <build> element, that's for build plugins.
 
K. Tsang
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After playing with it a bit, I have abandon the main class thing in WAR file. Actually I got to the point I got everything in order but when I run it, the DB connection is null because the console (main class) can't get the JNDI stuff from the app server. And I thought making it to work (meaning using JDBC) is too much effort IMO.

So the new approach? Have a web page or controller to call the necessary web services. Since I still need to trigger it automatically using cron job or similar, I found there is a "start" command in Windows to open the browser and load the page.



 
Stephan van Hulst
Saloon Keeper
Posts: 12154
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you maybe explain more about the purpose of your application? What does the web application do? What do you want the main class to do?
 
K. Tsang
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephen for your curiosity.

The whole idea was that I need a) to export/import files to/from other systems for their processing and b) generate PDF report to end users every day. The functions are all done in web services.

So I was originally planning to have a main class (in the WAR file) to do that. But I figured if I was able to call main class, it won't get the DB connection from JNDI. Then fallback to just a regular (manual) service call (controller).

In fact, a colleague of mine actually simplify the whole thing: write of the controller thing, separate the service call into another project, use parameters to determine what web service.

Then I thought, better than my approach at first. No JDBC or DB thing to set up. Just a matter of plugging in the parms correctly. I can live with that.
 
    Bookmark Topic Watch Topic
  • New Topic