Generator-jhipster: WARs are not executed on Tomcat while jars are working

Created on 21 Feb 2020  Â·  23Comments  Â·  Source: jhipster/generator-jhipster

Overview of the issue

I export as war and when i try to remote machine tomcat, it gives error.

Motivation for or Use Case

I cant deploy to tomcat.

Reproduce the error

1- Use jhipster to generate spring + angular project with gradle
2- Export as war with that command:

./gradlew -Pwar clean bootWar

because

./gradlew -Pprod -Pwar clean bootWar

gives error:

FAILURE: Build failed with an exception.

  • What went wrong:
    Task 'bootWar??' not found in root project 'halil'. Some candidates are: 'bootJar', 'bootWar'.

  • Try:
    Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2s`

so , i use this:

`./gradlew -Pwar clean bootWar
then it gives war.
3- Put to tomcat. Then get error
4- Export as jar with that:

./gradlew -Pprod -Pjar clean bootJar
5- Use java -jar xx.jar to run and there is no error

Related issues


https://github.com/jhipster/generator-jhipster/issues/9829#issuecomment-589649434
https://github.com/jhipster/generator-jhipster/issues/5996

Suggest a Fix

I also tried to change new BaseHrefWebpackPlugin({ baseHref: to war file name but did not work

maybe tomcat versions

JHipster Version(s)

JHipster configuration

jhipster info
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:info
INFO! Options: from-cli: true
Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
[email protected] C:\Projects\WORK\halil
`-- [email protected]

##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.bpn.legolas",
      "nativeLanguage": "tr"
    },
    "jhipsterVersion": "6.7.1",
    "applicationType": "monolith",
    "baseName": "halil",
    "packageName": "com.bpn.legolas",
    "packageFolder": "com/bpn/legolas",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "no",
    "enableHibernateCache": false,
    "websocket": false,
    "databaseType": "no",
    "devDatabaseType": "no",
    "prodDatabaseType": "no",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "gradle",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "embeddableLaunchScript": false,
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1582210924944,
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": true,
    "nativeLanguage": "tr",
    "languages": ["tr", "al", "ar-ly"],
    "blueprints": []
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory


JDL entity definitions


Environment and Tools

java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

git version 2.21.0.windows.1

node: v12.14.1

npm: 6.13.4

yeoman: 3.1.1

yarn: 1.22.0

INFO! Congratulations, JHipster execution is complete!

Entity configuration(s) entityName.json files generated in the .jhipster directory

none

Browsers and Operating System


windows 10. chrome my machine
client machine is same too
tomcat version: 8.5
java:8

  • [x ] Checking this box is mandatory (this is just to show you read everything)

$$ bug-bounty $$ $100 area java

Most helpful comment

Here what I know, from my recent tests:

  • Maven + War (using java -jar *.war) -> KO
  • Maven + War + Tomcat -> KO
  • Gradle + War -> OK
  • Gradle + War + Tomcat -> KO
    That's why it's disabled in our CI currently (except for Gradle)

Then, I already discussed with @PierreBesson about it, and I think it's time for removing War packaging.
It requires too much effort to maintain it, for nothing.
It's broken since months, but no one wants to fix it.

So, @aydincaner : you are really welcome to provide a PR and propose a fix, as you're using War file.

All 23 comments

What are these 2 characters at the end of your gradle command? It seems to be the reason why your build fails:

$ ./gradlew -Pprod -Pwar clean bootWar��
What went wrong:
Task 'bootWar??'

Looks like character encoding issue or copy/pasting error.
Have you tried typing manually the command?

Although you're on Windows, you seem to be using git bash to run gradlew (because you're using ./gradlew), have you tried running from a simple command prompt or powershell window using .\gradlew.cmd ?

@gmarziou i edited question. And answers to your questions.

For *` ./gradlew *:

`$ ./gradlew

Task :bootRun

    ??? ???   ??? ????????? ????????   ??????? ????????? ????????? ????????
    ??? ???   ??? ????????? ????????? ???????? ????????? ????????? ?????????
    ??? ?????????    ???    ????????? ???????     ???    ???????   ?????????

??? ??? ????????? ??? ???????? ??????? ??? ??????? ????????
????????? ??? ??? ????????? ??? ???????? ??? ????????? ??? ????
??????? ??? ??? ????????? ??? ??????? ??? ????????? ??? ???

:: JHipster ? :: Running Spring Boot 2.2.4.RELEASE ::
:: https://www.jhipster.tech ::

2020-02-21 17:53:11.681 INFO 3180 --- [ restartedMain] com.bpn.legolas.HalilApp : Starting HalilApp on caydin-nb with PID 3180 (C:\Projects\WORK\halil\build\classes\java\main started by caydin in C:\Projects\WORK\halil)
2020-02-21 17:53:11.683 DEBUG 3180 --- [ restartedMain] com.bpn.legolas.HalilApp : Running with Spring Boot v2.2.4.RELEASE, Spring v5.2.3.RELEASE
2020-02-21 17:53:11.683 INFO 3180 --- [ restartedMain] com.bpn.legolas.HalilApp : The following profiles are active: dev,swagger
2020-02-21 17:53:13.799 DEBUG 3180 --- [ restartedMain] i.m.c.u.i.logging.InternalLoggerFactory : Using SLF4J as the default logging framework
2020-02-21 17:53:13.976 DEBUG 3180 --- [ restartedMain] com.bpn.legolas.config.WebConfigurer : Registering CORS filter
2020-02-21 17:53:13.998 INFO 3180 --- [ restartedMain] com.bpn.legolas.config.WebConfigurer : Web application configuration, using profiles: dev
2020-02-21 17:53:13.999 INFO 3180 --- [ restartedMain] com.bpn.legolas.config.WebConfigurer : Web application fully configured
2020-02-21 17:53:14.123 DEBUG 3180 --- [ restartedMain] c.b.legolas.security.jwt.TokenProvider : Using a Base64-encoded JWT secret key
2020-02-21 17:53:15.234 DEBUG 3180 --- [ restartedMain] c.bpn.legolas.config.AsyncConfiguration : Creating Async Task Executor
2020-02-21 17:53:15.703 DEBUG 3180 --- [ restartedMain] i.g.j.c.apidoc.SwaggerAutoConfiguration : Starting Swagger
2020-02-21 17:53:15.711 DEBUG 3180 --- [ restartedMain] i.g.j.c.apidoc.SwaggerAutoConfiguration : Started Swagger in 7 ms
2020-02-21 17:53:16.214 ERROR 3180 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Web server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 10s
7 actionable tasks: 2 executed, 5 up-to-date`

from cmd.

On powershell,

/gradlew -Pprod -Pwar clean bootWar

works and gives war and again it does not work at tomcat. (SO
./gradlew -Pprod -Pwar clean bootWar AND ./gradlew -Pwar clean bootWar are exporting)

@gmarziou it is my question. And same errors :(

image

this is inside static/app

Here what I know, from my recent tests:

  • Maven + War (using java -jar *.war) -> KO
  • Maven + War + Tomcat -> KO
  • Gradle + War -> OK
  • Gradle + War + Tomcat -> KO
    That's why it's disabled in our CI currently (except for Gradle)

Then, I already discussed with @PierreBesson about it, and I think it's time for removing War packaging.
It requires too much effort to maintain it, for nothing.
It's broken since months, but no one wants to fix it.

So, @aydincaner : you are really welcome to provide a PR and propose a fix, as you're using War file.

Maven + war (jhipster version 6.5.1) + tomcat
worked for me once, but then I switched to jar

@geyuqiu jar with gradle worked also in tomcat?

@pascalgrimaud i dont think i can do that PR. I need too much time

Ajd i am putting two screenshots. They seem maybe helpful. The error in the console and in the network tab.

Annotation 2020-02-24 121554

Annotation 2020-02-24 121821

I created angular + spring with maven this time. Changed jar to war in pomxml and put to webapp in tomcat. but similar errors again

image

@geyuqiu jar with gradle worked also in tomcat?

@pascalgrimaud i dont think i can do that PR. I need too much time

Ajd i am putting two screenshots. They seem maybe helpful. The error in the console and in the network tab.

Annotation 2020-02-24 121554

Annotation 2020-02-24 121821

've never had a great relationship with gradle, maybe it was because of unclear error messages of missing gradle dependencies I don't remember. I could be wrong because of Gradle improvements in the last few years. Nonetheless... I tried to avoid that, except for Android, where there are no alternatives xD

@caneraydinbey Based on the screenshots, you are deploying under a context path, but did not configure the baseHref. In your case it should be /halil-2-0.0.1-SNAPSHOT/ (configure it here)

@ruddell for halil2\webpackwebpack.common.js I changed this line:

new BaseHrefWebpackPlugin({ baseHref: '/halil-2-0.0.1-SNAPSHOT' })

and then repackaged with maven.

Then i put again under webapps undet tomcat and started:

image

When i go to

http://localhost:8080/halil-2-0.0.1-SNAPSHOT/

it gives errors again:

image

Network tab:

image

I use intellij idea package option from maven menu:

image

I also ran from powershell:

mvn -Pdev package

image

this time it did not bring it:

image

tomcatlogs:

image

tomcat version:

C:\Users\caydin\Downloads\WORK\apache-tomcat-9.0.31-windows-x64\apache-tomcat-> 9.0.31>java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo > Server version: Apache Tomcat/9.0.31 Server > built: Feb 5 2020 19:32:12 UTC Server number: > > 9.0.31.0 OS Name: Windows 10 > OS Version: 10.0 Architecture: > > amd64 JVM Version: 1.8.0_231-b11 > JVM Vendor: Oracle Corporation

java version:

bin>java -version java version "1.8.0_231" Java(TM) SE Runtime Environment (build 1.8.0_231-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

@caneraydinbey Your baseHref needs to match the baseHref in my last message, you forgot the trailing slash. It will apply to both dev and prod, so you may want to copy the BaseHrefWebpackPlugin config to webpack.prod.js and only apply it there (or configure the same context path in dev).

I spent some time on this and don't see any issues at least with maven. Here is what I tried and worked for me:

  1. Generate session authentication based monolithic project with name as sessionapp
  2. Change the baseHref in the webpack.common.js to /sessionapp/
  3. Create a war using ./mvnw -Pprod,war clean verify -DskipTests
  4. Rename the generated war from sessionapp-0.0.1-SNAPSHOT.war to sessionapp.war so that it matches the baseHref
  5. Copy the sessionapp.war to the tomcat's webapps directory and post deployment, access the application with URL: http://localhost:8080/sessionapp/

Post step #3, if you want to deploy the generated sessionapp-0.0.1-SNAPSHOT.jar using java -jar:

  1. Rename the generated jar from sessionapp-0.0.1-SNAPSHOT.jar to sessionapp.jar so that it matches the baseHref
  2. Specify context path as environment variable or as a command line parameter and run the jar. I tried with command line parameter using command java -jar sessionapp.jar --server.servlet.context-path=/sessionapp and post deployment, access the application with URL http://localhost:8080/sessionapp/

@pascalgrimaud , @aydincaner - Can you try following above steps to see if that also works for you?

@vishal423 : thanks for having a look, I'll try your steps.
On your side, did you try to launch war file directly, as it should be executable file ?

@vishal423 :

  • I have no problems, following your steps, it works well
  • now, I only have problem when starting war from command line:
➜ java -jar target/jhburger.war            
aucun attribut manifest principal dans target/jhburger.war

@pascalgrimaud, I also see the same issue with executable war. Most likely, it's an issue with maven-war-plugin configurations. If no one else is looking into it, I can try to spend some time over the next few days.

@vishal423 : yes please, if you can

@pascalgrimaud, per my analysis, the war generated with inclusion of war maven profile is not executable. I actually don't see much usefulness of this war as it can contain conflicting dependencies that should be provided by container and would personally prefer to remove it.

IMO, the correct steps to generate a war ( + executable) should be:

  1. Generate Jhipster application (e.g. session authentication based monolithic project) with name as sessionapp
  2. Change the baseHref in the webpack.common.js to /sessionapp/
  3. In pom.xml, change packaging to war
  4. In pom.xml, change scope of spring-boot-starter-undertow to provided
  5. Create a war (executable and original) using ./mvnw -Pprod clean verify -DskipTests
  6. Rename the generated war from sessionapp-0.0.1-SNAPSHOT.war to sessionapp.war so that it matches the baseHref
  7. Copy the sessionapp.war (either executable or original) to the tomcat's webapps directory and post deployment, access the application with URL: http://localhost:8080/sessionapp/
  8. You can also run the executable war as java -jar sessionapp.war --server.servlet.context-path=/sessionapp and post deployment, access the application with URL http://localhost:8080/sessionapp/

There was an issue with executable war generated in step 3, that I have fixed in a PR.

Agree with you @vishal423
So for me, we just need to:

@vishal423 : can you do the documentation part plz ? Then I think we can close this ticket, with the bounty for you

Closing this as both PR have been merged
Thanks a lot @vishal423 :)

What about gateway jhipster project? @vishal423 , I got the above same error, following your steps:

webpack.common.js
template: './src/main/webapp/index.html', chunks: ['polyfills', 'main', 'global'], chunksSortMode: 'manual', inject: 'body', base: '/', base: '/gateway', }),
.../swagger-ui/index.html
axios.get("/swagger-resources").then(function (response) { response.data.forEach(function (resource) { urls.push({"name": resource.name, "url": resource.location}); urls.push({"name": resource.name, "url": "/gateway"+resource.location}); });
pom.xml
.... <packaging>war</packaging> .... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> <scope>provided</scope> </dependency>

image

@rennydonny please open a new issue with all required details rather than commenting a 7 months old issue

@rennydonny, I just tried with a gateway project and don't see any issue. In your shared configurations, you have missed the trailing slash and base: '/gateway' should be base: '/gateway/'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pascalgrimaud picture pascalgrimaud  Â·  3Comments

sdoxsee picture sdoxsee  Â·  4Comments

DanielFran picture DanielFran  Â·  3Comments

dronavallisaikrishna picture dronavallisaikrishna  Â·  3Comments

RizziCR picture RizziCR  Â·  3Comments