Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle create war and jar from same project

Im creating a java rest service using spring mvc, gradle and tomcat. I want to create a war from this project to be deployed in tomcat, and I want a jar from all model packages. I managed to create war and it works well. But I don't know to create a jar from my specified classes to be used as a client jar. I know i have to use include('com/a/b/**/model/**') for selecting classes but thats all. This jar i want to be installed in .m2 local repo so it can be used as a dependency for another projects. Below is my build.gradle file:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'maven'
apply from: 'dependencies.gradle'

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
     mavenCentral()
     mavenLocal()
}

def tomcatHome = 'E:\\apache-tomcat-7.0.62'

//change the name of war because default it is mywar.1.0.0.war
war.archiveName "mywar.war"

//move the war into tomcat webapps folder
task deployToTomcat(type: Copy) {
    from war
    into "$tomcatHome/webapps"
}
like image 406
user3258772 Avatar asked Oct 12 '25 15:10

user3258772


1 Answers

You should split the module into two modules: the API JAR and the WAR. Depend on the API JAR from the WAR.

like image 189
Johan Stuyts Avatar answered Oct 14 '25 04:10

Johan Stuyts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!