ccc
ccc

Reputation: 2385

How to build a WAR file to deploy on Tomcat from a JHipster Spring Boot project?

I created a project with JHipster, but made changes and added stuff to it. It runs ok when ran as a Spring Boot project from the IDE (Intellij), but when trying to build a WAR and deploy it on a Tomcat 7, it fails with the following stack trace:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [org/springframework/boot/autoconfigure/transaction/jta/JndiJtaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)
        ... 41 more
Caused by: java.lang.IllegalStateException: No JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'
        at org.springframework.transaction.jta.JtaTransactionManager.checkUserTransactionAndTransactionManager(JtaTransactionManager.java:494)
        at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(JtaTransactionManager.java:436)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
        ... 51 more

I also tried:

mvn -Pprod clean package

but that also fails with:

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.35 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket gsod2iXnNubgdt_gVHUZ with id 68003640
PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR
  ReferenceError: Can't find variable: google
  at C:/Dev/workspaces/myProject/src/main/webapp/scripts/components/view/geoChart.directive.js:9
PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR
  ReferenceError: Can't find variable: google
  at C:/Dev/workspaces/myProject/src/main/webapp/scripts/components/view/geoChart.directive.js:9

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 0 of 0 ERROR (1.301 secs / 0 secs)

Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

I have added the Google GeoChart, and that seems to cause an issue.

What I would like to get is a classic WAR that I can deploy on Tomcat, but I am obviously doing something wrong and I don't know what.

Thank you.

Upvotes: 2

Views: 6575

Answers (2)

Sanjay Rawat
Sanjay Rawat

Reputation: 2364

Also update the Karma version from v0.12.35 to Karma v0.13.19.

That is, set "karma": "0.13.19", in package.json and rum npm install. More info here.

Upvotes: 0

sdoxsee
sdoxsee

Reputation: 4681

Are you using the *.war.original or the *.war?

I think you'd want to put the *.war.original in tomcat after renaming it to a .war file.

see the documentation: http://jhipster.github.io/production/

To package the application as a "production" WAR, type:

mvn -Pprod package

Or when using Gradle:

gradlew -Pprod bootRepackage

This will generate two files (if your application is called "jhipster"):

target/jhipster-0.0.1-SNAPSHOT.war target/jhipster-0.0.1-SNAPSHOT.war.original The first one is an executable WAR file (see next section to run it). It can also be deployed on an application server, but as it includes the Tomcat runtime libs, you will probably get some warnings, that's why we recommend you use the second, ".original" file if you want to deploy JHipster on an application server.

Once you have deployed you WAR file on your application server:

It will use by default the "dev" profile It can run in "production mode" if you trigger the "prod" profile (there are several ways to trigger a Spring profile, for example you can add -Dspring.profiles.active=prod to your JAVA_OPTS when running your server)

Upvotes: 3

Related Questions