Skip to main content

Posts

Gradle : How To Exclude Files and Packages from a Jar file

How To Exclude File from a Jar file. Gradle task Jar has a property excludes which takes an array as an input and exclude these files from the Jar file it creates. Let's assume the following directory structure Following example excludes files from the Jar file. task createExcludingFiles(type :Jar){ from ('src'){ excludes = ["main/java/com/ekiras/demo/D.java","main/java/com/ekiras/demo/E.java"] } } This will exclude files D.java , E.java from the jar file. Run the gradle task using command gradle -q createExcludingFiles . The Jar file created will have the following files. META-INF/ META-INF/MANIFEST.MF main/ main/java/ main/java/com/ main/java/com/ekiras/ main/java/com/ekiras/demo/ main/java/com/ekiras/demo/A.java main/java/com/ekiras/demo/C.java main/java/com/ekiras/demo/F.java main/java/com/ekiras/demo/B.java main/java/com/ekiras/demo/p1/ main/java/com/ekiras/demo/p1/X.java main/java/com/ekiras/demo/p1/Z.java main/java/com/ekiras/de...

Gradle : How to create a Jar file

How to name a Jar file Lets take the following jar file for explaning the jar naming conventions. customName_wrapper_2.0.1_SNAPSHOT.jar A jar file has the following properties Property Description baseName customName appendix wrapper version 2.0.1 classifier SNAPSHOT archiveName - Here property archiveName if specified will override all the other naming conventions like baseName etc. It should be a fully qualified name of the Jar including the extension (.jar) Other Properties of Gradle Task :: Jar Property Description destinationDir Destination where jar is to be created manifest Include Manifest file from Directory from where files are to be read Creating a Jar file Let's assume the following directory structure Create a Jar file with all files. We can write a gradle task to include all files in src to our jar file as follows task createAll(type : Jar){ from 'src' } When we run the gradle task as gradle -q createAll will give the following files in the jar META-I...

Tomcat : How to start Tomcat on more than one Port.

How to start Tomcat on more than one Port. Tomcat settings can be found in TomcatFolder/conf/server.xml file. Root element of the configuration is Server tag. You can add multiple Service under Server tag for running tomcat on more than one port. Default Service Configuration should look as follows < Service name = "Catalina" > < Connector port = "8080" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> < Connector port = "8009" protocol = "AJP/1.3" redirectPort = "8443" /> < Engine name = "Catalina" defaultHost = "localhost" > < Realm className = "org.apache.catalina.realm.LockOutRealm" > < Realm className = "org.apache.catalina.realm.UserDatabaseRealm" resourceName = "UserDatabase" /> </ Realm > ...

Tomcat : How to change default port 8080 of Tomcat

How to change default port 8080 of Tomcat Look for the file server.xml in folder path-to-Tomcat/conf/ This file containes the configuration for tomcat. Look for the following lines in this file. < Connector port = "8080" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> Connector port="8080" defines the port on which the tomcat will run. If you want to run tomcat on any port other than 8080 then you can just change the port number here. e.g Running Tomcat on port 8090 < Connector port = "8090" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> e.g Running Tomcat on port 9000 < Connector port = "9000" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> Also Read How to c...

Tomcat : How to change Deployment directory from webapp to custom Directory.

How to change Working Directory of Tomcat to Custom Directory Default Tomcat working directory is webapp . If you want to change this to some other directory then you can follow the steps below. Open the server.xml file. You can find this file in conf/ directory of your tomcat folder. Find the following line in the file < Host name = "localhost" appBase = "webapps" unpackWARs = "true" autoDeploy = "true" > It states the following things name="localhost" - name of the server appBase="webapps" - working directory of tomcat where applications are deployed unpackWARs="true" - if tomcat should unpack war files. autoDeploy="true" - if tomcat should auto deploy changes How to change Work directory of tomcat. To change the work directory from webapp to some other directory you can give the absolute path to the directory where you want to deploy apps. relative path to the directory...

Gradle : How to list files inside a Jar, Zip Tar Files in Gradle Task

How to load and read files in Gradle Project. The Gradle Project Api has the following methods for using files. file() - to load and read a particular file files() - to load and read multiple files fileTree() - to load and read file hierarchy in a directory or folder zipTree() - to load and read a zip file (includes Jar , War and Ear files) tarTree() - to load and read a tar file How to list files inside a Zip file Jar File and Tar file Lets say we have a file structure as shown in image below. Following Gradle task will list the files inside a zip file, jar file and a tar file at the location "src/main/resources/archives/" task showFiles(){ doLast{ FileTree zipFiles = zipTree("src/main/resources/archives/resources.zip"); FileTree jarFiles = zipTree("src/main/resources/archives/resources.jar"); FileTree tarFiles = tarTree("src/main/resources/archives/resources.tar.gz"); println " \n#Contents of Zip ...

Gradle : Difference between File, FileCollection and FileTree in Gradle

Difference Between File, FileCollection and FileTree in Gradle File FileCollection FileTree File is from java.io package FileCollection is from org.gradle.api.file package FileTree is from org.gradle.api.file package File represents a single file. FileCollection represents a collection of files FileTree represents hierarchy of files in a directory or folder. Difference Between File, FileCollection and FileTree Suppose we have a directory structure as shown in image below. We can write a gradle task as shown below task loadFiles(){ doLast{ File file = file('src/main/resources/sample1.txt') println file.name println "\n" FileCollection collection = files('src/main/resources/sample1.txt','src/main/resources/sample2.txt') collection.each { println it.name } println "\n" FileTree tree = fileTree('src') tree.each { println it.name ...