0

We have a project where we're creating a web-app deployed to JBoss. Maven, war packaging, etc. Now the client has a requirement that we include a command-line-interface for the app, saying a user should also be able to fire up a main method somewhere inside the war (no matter whether the app is currently deployed on JBoss or not).

I'm kind of at a loss. I've searched here and many different searches on Google, and I've found the Jetty / Jenkins examples, but those examples only seem to have one class file needed to run as a jar.

Currently the war structure for the project is this:

-resources
-META-INF
---MANIFEST.MF, et al
-WEB-INF
---web.xml, classes(com/*), lib, et al

I'm having Maven set up the MANIFEST.MF file with the Main-Class for the class I want to call using java -jar. But then the structure of the war seems to need to follow a "normal" jar structure, like this:

-resources
-com/*/main.class
-META-INF
---MANIFEST.MF, et al
-WEB-INF
---web.xml, classes(com/*), lib, et al

But then the main.class depends on other classes in the app, so I find myself putting more and more of the code in both places, for the jar functionality and the war as well.

Ok, so I've used Maven + antrun to copy the class files from WEB-INF/classes to the root of the war file. Now there are jars that the classes depend on (for instance, log4j). So NOW I find myself using antrun to unjar the necessary jars, placing THOSE class files in the root of the war...

This seems...crazy. Is there a (better) way?

edited with more information The CLI functionality needs to access a database, so there are unfortunately many classes needed (all the DAO/EBO/configuration classes)

  • 3
    Would it be feasible to ship both a war and a jar that basically contain the same functionality? Splitting your code into 3 modules: core, app, webapp could then help. – vikingsteve Sep 17 '13 at 07:44
  • Other option could be to create a main class which will use a custom class-loader to find and load classes from `WEB-INF/classes/` path inside your packaged war. This main class you can keep at root path inside war. This is not a simple solution though. – Bimalesh Jha Sep 17 '13 at 07:48
  • Here's an answer from me for a similar question: http://stackoverflow.com/a/12578056/1350762. It is using the same idea as @vikingsteve mentioned, i.e. split it up into distinct modules. Here is another answer: http://stackoverflow.com/a/12693124/1350762 – maba Sep 17 '13 at 07:54
  • Thanks for the replies. I had seen that question here, and I think it's my fallback last-ditch option. Also the main class would use many jars that the webapp uses, so I'm not sure what to do with that. Would the war (with included jars in WEB-INF/lib) count as being on the classpath for the jar? – Phillip Atkinson Sep 17 '13 at 08:00
  • Bimalesh, I also considered this, but like you say, it's not a simple solution :) There would be many, many classes loaded. I've updated my question with a few more specifics. – Phillip Atkinson Sep 17 '13 at 08:07

0 Answers0