How to Run a Class in a War from the Command Line

Run JAVA war file from command line with classpath to start API

The main issue is most likely because the class files isn't incorporated into the silverkissen.war file. Meaning there is no Main function in the war file itself. Or that the entry function is some where else.

Or that it's packaged in some mysterious way that is beyond my understanding that's specific to maven, heroku etc.

But assuming you're standing in the project root structure, one level before the target folder usually where you'd normally have src, target, pom.xml and system.properties. I'd try running the following:

java -cp target/classes:target/dependency/* se.consys.silverkissen.heroku.Main

And if you're on Windows that'd be:

java -cp target\classes;target\dependency\* se.consys.silverkissen.heroku.Main

That aught to do it. This will execute your project with class-path's in the runtime. Assuming my limited knowledge of Java is correct.

Someone with more experience can probably explain in detail why this would work.

Execute Java Class from JAR on Linux command line

I just figured this out. As I said, the code itself works great from within Eclipse and is unit tested. When you run a class within Eclipse, you can run a Java Class as a standard Java application, and it will create a Configuration for you with a setup classpath. There is even a button that says "Show Command Line" which showed the full classpath, call to java, any -D arguments, and the actual class.

So, there were two things that I missed:

1) I needed to include ALL the jars that were associated with this class. I know that was mentioned in the comments, and I had tried that because I suspected it was the case.

2) However, what I messed up on was the separator between jars. I tried comma (,) and semi-colon (;) before figuring out that I needed the colon (:). Looking the command-line that Eclipse put together clued me in on that.

It was asked, did I try to execute this on the command-line before I did the script, and the answer is: I did not. I just thought I'd go to the script directly.

BTW ... I figured that having some standalone utilities with my overall web-application wasn't a huge problem. It wasn't worth it to create a whole new project for one utility.

Now that I know this script runs, now I can put it on a cron job.

Thanks for the help. And I hope this helps someone else.

Running .war files?

war file, unlike a jar file needs to be deployed in a servlet container. e.g.: Tomcat, Jetty. It's not supposed to be run via the command line. If you do want to run it via the command line, you would probably need to take care of starting up the servlet container yourself. e.g.: start jetty server instance from code and deploy your war inside it.



Related Topics



Leave a reply



Submit