how to use gradle command to generate proper war file - java

Good day,
Base on this page, https://www.eclipse.org/webtools/community/tutorials/TopDownAxis2WebService/td_tutorial.html,
I am using eclipse to create a Top Down java bean web service, by using Axis2 runtime.
The different of mine, is I am using Red Hat JBoss EAP as my server.
After done the thing, I am now want to generate the war file and deploy in another Red Hat JBoss server. I can successfully generate the war file by right click on the project in my eclipse and export it as war, and the war file can successfully deploy into Jnoss server and the service can up successfully.
In the other way, I would like to try to use gradle command to generate the war file, instead of using eclipse to generate. Thus I run gradle clean build command to generate the war file. Yes, the war file can be generated but the file size lesser 10MB if compare with the one I generate throw eclipse.
And the war generate by gradle command, I will hit 404 when I view the service after I deployed into my Jboss server.
I extract both the war to compare, and found that the one using command is lack of the axis2-web library folder.
The following is my screen shot:
eclipse generated war file and with the 3 folders after I extract the war:
gradle clean build generated war file and with the 2 folders after I extract the war:
As you can see, the one generate by gradle command, lack of the axis2-web library folder, thus I believe this is why it can be access successfully after deployed.
and the following is my build.gradle:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = "EAIDelegateBeanServiceSkeleton"
repositories {
mavenCentral()
maven {
url "https://packages.confluent.io/maven"
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile "com.google.guava:guava:17.0"
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'org.apache.kafka:kafka-clients:3.1.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'io.confluent:kafka-json-serializer:6.2.0'
compile "org.springframework.kafka:spring-kafka:2.6.13"
compile "org.springframework:spring-web:5.2.19.RELEASE"
testImplementation "junit:junit:4.12"
}
I would like to ask for help on how can I configure so that I can generate the correct war file by using gradle command.

I found out the solution is configure the webContent/web-inf under war in build.gradle:
war {
webInf { from 'WebContent/WEB-INF' }
}

Related

How to write gradle task to create war from react's built files?

I want to achieve below project structure ->
-- Project MyApp
-- out
-- myapp-client-war
-- myapp-client.war
-- myapp-server-war
-- myapp-server.war
-- myapp-client
-- dist (this folder will have index.html, bundle.js)
-- build.gradle
-- myapp-server
-- build.gradle
Using ReactJs for myapp-client and Java for myapp-server.
Out folder will have war files for client and server.
I could able to generate server war file using gradle 'war' plugin.
I want to achieve the same for react built files present in dist folder, i.e. to bundle those files as war, using the gradle's 'war' plugin.
My current client's build.gradle script ->
configure(project) {
apply plugin: 'war'
war {
archiveFileName = 'myapp-client.war'
destinationDirectory = file("$buildDir/myapp-client-ee-war")
}
task sourceJar(type: Jar) {
from "$projectDir/dist/"
}
}
This script is not creating war, Could someone please check what am I missing?
FYI : I have already tried with this solution but this uses 'webpack-war-plugin' package. And as per the requirement, I have to use gradle 'war' plugin.

include a gradle 'war' project in another project

I'm new to Gradle and trying to work out how to get my dependencies working correctly.
I have a project which builds a war using the 'war' plugin. I'd then like to use that project, and some other similar projects, to deploy those wars.
However, I can't work out how to make the project which is responsible for assembling these other projects dependent on the war projects.
The project 'war1' has a single 'war' method, I’ve tried the following
dependencies, none of which work:
dependencies {
war project(path: ':war1')
/* or */ compile project(path: ':war1')
/* or */ assemble project(path: ':war1')
}
Could not find method xxx() for arguments [DefaultProjectDependency{dependencyProject='project ':war1', configuration='default'}]
You can specify dependencies on .war artifacts in Gradle like this example...
dependencies {
runtime "org.jasig.cas:cas-server-webapp:3.5.2#war"
}
NOTE: this example is for an external dependency, not a dependency on another sub-project within the same multi-project setup. Looking at the api docs, it appears that you would do that like this...
dependencies {
runtime project(path: ':war1', configuration: 'war')
}
Also -- perhaps you could benefit from the Gradle WAR overlay plugin. This plugin allows you to "enhance" a war dependency by adding or tweaking a few files within it, and thereby provide some configuration choices that your project knows about, but the original war didn't.

Gradle is not place WebJar contents into the correct place in my Jar file

I've got a basic Java application in which I would like to use WebJars. I use Gradle as my build system. I would like to use the WebJars for Bootstrap and JQuery so I can easily reference and update them in my Spring-Boot/ThymeLeaf application. The application is basically the one from the form tutorial located here
As I understand it Gradle should place all the files from the WebJars into the META-INF folder in my Jar file. If I understand everything correctly the Spring-Boot resource handler will then load resource from META-INF/ when I reference something in my html page that starts with /webjars/
Unfortunately this doesn't work (yet). Since I see in Tomcat's log output that the resource handler is correctly installed. I decided to check if the files are actually in my Jar file.
When I extract my Jar file the META-INF folder only has a file called MANIFEST.MF with some information about Spring Boot. There is a BootStrap-3.3.7.Jar and a JQuery-3.2-1.Jar file in BOOT-INF/lib but I don't think that is where they are supposed to end up. (Or am I wrong and is there error somewhere in the resource handler?).
How do I tell gradle to do the right thing with these files when I run gradle build?
My gradle.build file looks like this:
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: "jacoco"
jar {
baseName = 'gs-serving-web-content'
version = '0.0.1'
}
bootRun {
addResources = true
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.webjars:jquery:3.2.1")
compile("org.webjars:bootstrap:3.3.7")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
Gradle is doing the right thing as the jars should be packaged in BOOT-INF/lib. The root of each jar in BOOT-INF/lib is then added to the classpath from where each its webjar related content in META-INF content should be found.
I'd recommend asking another question that focuses on what your application's doing at runtime. As far as I can tell, everything's working as it should at build time.

gradle project: error couldn't find main class

I have the following project structure:
Root project 'rmi-tutorial'
+--- Project ':client'
+--- Project ':lib'
\--- Project ':server'
The path to clients main class looks like this:
client/src/main/java/client/ComputePi.java
my build.gradle for the client subproject loooks like this:
dependencies {
compile project(':lib')
}
mainClassName = "ComputePi"
The main build.gradle file is this one:
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
repositories {
mavenCentral()
}
dependencies {
//compile project(':server')
//compile project(':client')
testCompile 'junit:junit:4.12'
}
version = '1.0'
jar {
manifest.attributes provider: 'gradle'
}
}
The generation of the jars works so far but the MANIFEST.MF file in the jar is wrong. It contains the following:
Manifest-Version: 1.0
provider: gradle
Where is my specified main class? When I try to execute the startscript that got created by the gradle application-plugin I get the error: couldn't find nor load main class
The jar contains all necessary class files
The application plugin does not produce a runnable JAR with Main-Class entry. Instead it generates a distribution with Windows and *nix start scripts where the main class is used and all libaries put to the class path.
If you want a runnable JAR, you have to configure it yourself, or use one of the plugins that produces a fat JAR, also including the dependencies into the runnable JAR (I don't like this, but it works if the target computer has the correct file associations set). If the target computer e. g. has associated JAR files with an archiving tool, double-clicking the JAR will open the JAR in the archiving tool, not run your application.
If you want to run your application, use gradlew run, or do gradlew installDist and then execute the application that is installed to build/install/.... That is how the application plugin works. With gradlew distZip or gradlew distTar you can create shippable archives of your application.

Why do xml configs of gradle dependencies go with "Gradle__" prefix? Intellij IDEA 13

Java Spring project with Gradle 1.9 and vertx. Local gradle distribution.
Some lines of build.gradle
apply plugin 'java'
apply plugin 'groovy'
apply plugin 'idea'
buildscript {
repositories {
jcenter()
}
}
repositories {
mavenCentral()
}
dependencies {
...
compile 'org.springframework:spring-context-support:3.2.5.RELEASE'
compile 'org.springframework:spring-aop:3.2.5.RELEASE'
compile 'org.springframework:spring-aspects:3.2.5.RELEASE'
...
}
I have an existing gradle project downloaded from git with xml configs in .idea/libraries folder named spring-aop_3_2_5_RELEASE.xml, for example, where we can find xml tag <library name="spring-aop-3.2.5.RELEASE">...</library>.
After I had imported this project new file Gradle__spring-aop_3_2_5_RELEASE.xml appeared with only difference in name attribute of the library tag: Gradle: spring-aop-3.2.5.RELEASE. So i have duplicate xml configs for dependencies. I wonder why my gradle added that prefix.
The prefix is hardcoded, IDEA 13 needs a reimport of your old Gradle projects that were created in IDEA 12. It's not obvious, but there will be a notification about it in the next update.
In the Gradle generated project you can exclude the library files from the version control, same for the .iml files that can be also ignored when using Maven. Other files can be still shared (like code style, run configurations, inspection profiles, etc). Check this document for details.

Categories

Resources