├── deploy.sh
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── src
└── main
│ ├── java
│ └── jayray
│ │ └── net
│ │ ├── orders
│ │ ├── Namespaces.java
│ │ ├── CustomerResource.java
│ │ ├── Address.java
│ │ ├── Customer.java
│ │ └── CustomerDao.java
│ │ ├── hello
│ │ ├── EchoResource.java
│ │ └── HelloWorldResource.java
│ │ └── JAXBContextResolver.java
│ ├── webapp
│ └── WEB-INF
│ │ └── web.xml
│ └── resources
│ └── log4j.properties
├── .gitignore
├── gradlew.bat
├── README.md
└── gradlew
/deploy.sh:
--------------------------------------------------------------------------------
1 | cp build/libs/jersey-starterkit.war $CATALINA_HOME/webapps/
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonray/jersey-starterkit/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/src/main/java/jayray/net/orders/Namespaces.java:
--------------------------------------------------------------------------------
1 | package jayray.net.orders;
2 |
3 | public class Namespaces {
4 | private Namespaces() {
5 | }
6 |
7 | public static final String OrdersNamespace = "http://jayray.net/orders";
8 | }
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Dec 20 15:05:43 EST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip
7 |
--------------------------------------------------------------------------------
/src/main/java/jayray/net/hello/EchoResource.java:
--------------------------------------------------------------------------------
1 | package jayray.net.hello;
2 |
3 | import javax.ws.rs.GET;
4 | import javax.ws.rs.Path;
5 | import javax.ws.rs.Produces;
6 | import javax.ws.rs.QueryParam;
7 |
8 | @Path("echo")
9 | public class EchoResource {
10 |
11 | @GET
12 | @Produces("text/plain")
13 | public String echo(@QueryParam("m") String message) {
14 | return "echo: " + message;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/jayray/net/orders/CustomerResource.java:
--------------------------------------------------------------------------------
1 | package jayray.net.orders;
2 |
3 | import javax.ws.rs.GET;
4 | import javax.ws.rs.Path;
5 | import javax.ws.rs.PathParam;
6 | import javax.ws.rs.Produces;
7 | import javax.ws.rs.core.MediaType;
8 |
9 | @Path("customer")
10 | public class CustomerResource {
11 |
12 | @GET
13 | @Path("id/{id}")
14 | @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
15 | public Customer getCustomer(@PathParam("id") String id) {
16 | CustomerDao customerDao = new CustomerDao();
17 | return customerDao.fetchCustomer(id);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Project structure related
2 | .classpath
3 | .project
4 | .settings
5 | .metadata
6 | tmp/**
7 | tmp/**/*
8 | *.tmp
9 | *.bak
10 | *.swp
11 | *~.nib
12 | local.properties
13 | .loadpath
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # Build related
20 | bin/**
21 | build
22 | .gradle
23 | *.class
24 |
25 | # Package Files #
26 | *.jar
27 | *.war
28 | *.ear
29 |
30 | # Scala Related Files
31 | *.log
32 | *.class
33 |
34 | # sbt specific
35 | dist/*
36 | target/
37 | lib_managed/
38 | src_managed/
39 | project/boot/
40 | project/plugins/project/
41 |
42 | # Scala-IDE specific
43 | .scala_dependencies
--------------------------------------------------------------------------------
/src/main/java/jayray/net/hello/HelloWorldResource.java:
--------------------------------------------------------------------------------
1 | package jayray.net.hello;
2 |
3 | import javax.ws.rs.GET;
4 | import javax.ws.rs.Path;
5 | import javax.ws.rs.Produces;
6 | import javax.ws.rs.core.MediaType;
7 |
8 | import org.apache.log4j.Logger;
9 |
10 | @Path("hello")
11 | public class HelloWorldResource {
12 | private static final Logger logger = Logger.getLogger(HelloWorldResource.class);
13 |
14 | @GET
15 | @Produces(MediaType.TEXT_PLAIN)
16 | public String sayhello() {
17 | logger.debug("sample debug message");
18 | logger.info("sample info message");
19 | logger.warn("sample warning message");
20 | logger.error("sample error message");
21 | return "hello";
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/jayray/net/orders/Address.java:
--------------------------------------------------------------------------------
1 | package jayray.net.orders;
2 |
3 | import javax.xml.bind.annotation.XmlAccessType;
4 | import javax.xml.bind.annotation.XmlAccessorType;
5 | import javax.xml.bind.annotation.XmlAttribute;
6 | import javax.xml.bind.annotation.XmlElement;
7 |
8 | @XmlAccessorType(XmlAccessType.NONE)
9 | public class Address {
10 | @XmlElement
11 | private String city;
12 | @XmlElement
13 | private String state;
14 | @XmlAttribute
15 | private String addressType;
16 |
17 | public String getCity() {
18 | return city;
19 | }
20 |
21 | public void setCity(String city) {
22 | this.city = city;
23 | }
24 |
25 | public String getState() {
26 | return state;
27 | }
28 |
29 | public void setState(String state) {
30 | this.state = state;
31 | }
32 |
33 | public String getAddressType() {
34 | return addressType;
35 | }
36 |
37 | public void setAddressType(String addressType) {
38 | this.addressType = addressType;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/jayray/net/orders/Customer.java:
--------------------------------------------------------------------------------
1 | package jayray.net.orders;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.xml.bind.annotation.XmlElement;
7 | import javax.xml.bind.annotation.XmlRootElement;
8 |
9 | @XmlRootElement(namespace = Namespaces.OrdersNamespace)
10 | public class Customer {
11 | private String id;
12 | private String name;
13 | private List
addresses = new ArrayList();
14 |
15 | public String getId() {
16 | return id;
17 | }
18 |
19 | public void setId(String id) {
20 | this.id = id;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 |
31 | @XmlElement(name = "address", namespace = Namespaces.OrdersNamespace)
32 | public List getAddresses() {
33 | return addresses;
34 | }
35 |
36 | public void setAddresses(List address) {
37 | this.addresses = address;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/jayray/net/JAXBContextResolver.java:
--------------------------------------------------------------------------------
1 | package jayray.net;
2 |
3 | import javax.ws.rs.ext.ContextResolver;
4 | import javax.ws.rs.ext.Provider;
5 | import javax.xml.bind.JAXBContext;
6 |
7 | import jayray.net.orders.Address;
8 | import jayray.net.orders.Customer;
9 | import jayray.net.orders.CustomerResource;
10 |
11 | import com.sun.jersey.api.json.JSONConfiguration;
12 | import com.sun.jersey.api.json.JSONJAXBContext;
13 |
14 | @Provider
15 | @SuppressWarnings("rawtypes")
16 | public class JAXBContextResolver implements ContextResolver {
17 |
18 | private JAXBContext context;
19 | // defining these explicitly is only required to state to use the configuration for natural json handling
20 | // https://jersey.java.net/nonav/apidocs/1.5/jersey/com/sun/jersey/api/json/JSONConfiguration.Notation.html#NATURAL
21 | private Class[] types = { Address.class, Customer.class, CustomerResource.class };
22 |
23 | public JAXBContextResolver() throws Exception {
24 | this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), types);
25 | }
26 |
27 | @Override
28 | public JAXBContext getContext(Class> objectType) {
29 | for (Class type : types) {
30 | if (type == objectType) {
31 | return context;
32 | }
33 | }
34 | return null;
35 | }
36 | }
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | jersey sample
4 |
5 | jersey
6 | com.sun.jersey.spi.container.servlet.ServletContainer
7 |
8 | com.sun.jersey.config.property.packages
9 | jayray
10 |
11 |
12 |
15 |
21 | 1
22 |
23 |
24 | jersey
25 | /rest/*
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/main/java/jayray/net/orders/CustomerDao.java:
--------------------------------------------------------------------------------
1 | package jayray.net.orders;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class CustomerDao {
7 |
8 | public Customer fetchCustomer(String id) {
9 | List customers = loadCustomers();
10 |
11 | Customer match = null;
12 | for (Customer potentialMatch : customers) {
13 | if (potentialMatch.getId().matches(id)) {
14 | match = potentialMatch;
15 | break;
16 | }
17 | }
18 | return match;
19 | }
20 |
21 | private List loadCustomers() {
22 | ArrayList customers = new ArrayList();
23 | Customer customer;
24 | Address address;
25 |
26 | customer = new Customer();
27 | customer.setId("1");
28 | customer.setName("Mighty Pulpo");
29 | address = new Address();
30 | address.setCity("Austin");
31 | address.setState("TX");
32 | address.setAddressType("home");
33 | customer.getAddresses().add(address);
34 | address = new Address();
35 | address.setCity("Sterling");
36 | address.setState("VA");
37 | address.setAddressType("work");
38 | customer.getAddresses().add(address);
39 | customers.add(customer);
40 |
41 | customer = new Customer();
42 | customer.setId("2");
43 | customer.setName("Bob Jones");
44 | address = new Address();
45 | address.setCity("San Antonio");
46 | address.setState("TX");
47 | address.setAddressType("home");
48 | customer.getAddresses().add(address);
49 | address = new Address();
50 | address.setCity("Reston");
51 | address.setState("VA");
52 | address.setAddressType("work");
53 | customer.getAddresses().add(address);
54 | customers.add(customer);
55 |
56 | customer = new Customer();
57 | customer.setId("3");
58 | customer.setName("Big Oil");
59 | address = new Address();
60 | address.setCity("Houston");
61 | address.setState("TX");
62 | address.setAddressType("home");
63 | customer.getAddresses().add(address);
64 | address = new Address();
65 | address.setCity("Ashburn");
66 | address.setState("VA");
67 | address.setAddressType("work");
68 | customer.getAddresses().add(address);
69 | customers.add(customer);
70 |
71 | return customers;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.debug=true
2 |
3 | #Log Levels = (Most) DEBUG,INFO,WARN,ERROR,FATAL (Least) or ALL to obtain all logs
4 | # set root logger to debug level to output to the standard output/console appender
5 | log4j.threshold=ALL
6 | log4j.rootLogger=ALL, mhpC, mhpF, mhpFE, mhpFD
7 |
8 | log4j.logger.net.jayray=DEBUG
9 |
10 |
11 | # this defines the "C" (console) appender to be used with the root logger. The "C" is an arbitrary name. It specifies to send data to console (picked up by glassfish to send to its logger)
12 | log4j.appender.mhpC=org.apache.log4j.ConsoleAppender
13 | # info on layout pattern: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
14 | log4j.appender.mhpC.layout=org.apache.log4j.PatternLayout
15 | log4j.appender.mhpC.Threshold=DEBUG
16 | log4j.appender.mhpC.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss,SSS}][%t][%-5p]%-50.50c: %m%n
17 |
18 | # this defines the "F" (file) appender to be used with the root logger. The "F" is an arbitrary name. It specifies to send data to log file
19 | log4j.appender.mhpF=org.apache.log4j.RollingFileAppender
20 | log4j.appender.mhpF.File=/restapi/logging/restapi.log
21 | log4j.appender.mhpF.MaxFileSize=10MB
22 | log4j.appender.mhpF.MaxBackupIndex=10
23 | log4j.appender.mhpF.layout=org.apache.log4j.PatternLayout
24 | log4j.appender.mhpF.Threshold=INFO
25 | log4j.appender.mhpF.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss,SSS}][%t][%-5p]%-50.50c: %m%n
26 |
27 | # this defines the "FD" (file, debug) appender to be used with the root logger. The "FD" is an arbitrary name. It specifies to send debug data to log file
28 | log4j.appender.mhpFD=org.apache.log4j.RollingFileAppender
29 | log4j.appender.mhpFD.File=/restapi/logging/restapi.debug.log
30 | log4j.appender.mhpFD.MaxFileSize=10MB
31 | log4j.appender.mhpFD.MaxBackupIndex=10
32 | log4j.appender.mhpFD.layout=org.apache.log4j.PatternLayout
33 | log4j.appender.mhpFD.Threshold=ALL
34 | log4j.appender.mhpFD.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss,SSS}][%t][%-5p]%-100.100c: %m%n
35 |
36 |
37 | # this defines the "FE" (file, error) appender to be used with the root logger. The "FE" is an arbitrary name. It specifies to send error data to log file
38 | log4j.appender.mhpFE=org.apache.log4j.RollingFileAppender
39 | log4j.appender.mhpFE.File=/restapi/logging/restapi.error.log
40 | log4j.appender.mhpFE.MaxFileSize=10MB
41 | log4j.appender.mhpFE.MaxBackupIndex=10
42 | log4j.appender.mhpFE.layout=org.apache.log4j.PatternLayout
43 | log4j.appender.mhpFE.Threshold=ERROR
44 | log4j.appender.mhpFE.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss,SSS}][%t][%-5p]%-100.100c: %m%n
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Overview
2 | ========
3 | This is a starter project using jax-rs / jersey. I've created this because I often find myself wanting to expirement with something that needs a webservice, and this gives me a starting spot. Clone or fork and use as needed.
4 |
5 | Note: if you like this version, I highly recommend checking out the sample dropwizard implemenation (https://github.com/jasonray/jersey-starterkit/tree/dropwizard), much better for quick implemenations of java based web services. I love me some dropwizard. Until I discovered node/express.
6 |
7 | How-to run
8 | ==========
9 | 0.1) Pre-req
10 |
11 | You will need the following installed:
12 | Java
13 | Gradle (optional)
14 | A java web container, such as Tomcat.
15 |
16 | If you are on a mac, I recommend to do the following:
17 | - install Homebrew (see: http://brew.sh/)
18 | - install Java and Tomcat:
19 | ```
20 | brew cask install java
21 | brew install tomcat
22 | ```
23 |
24 | If you will be using Tomcat, you will likely want to make sure you have CATALINA_HOME set.
25 | On a mac, edit your profile
26 | ```
27 | vi ~/.bash_profile
28 | ```
29 |
30 | and then add the following (replacing with the directory where you Tomcat instance is deployed:
31 | ```
32 | export CATALINA_HOME=/usr/local/Cellar/tomcat/x.x.x/libexec
33 | ```
34 |
35 | 1) Compile
36 | The project compiles using gradle. If you already have gradle installed, compile using:
37 | ```
38 | gradle build
39 | ```
40 |
41 | If you do not have gradle installed, you can utilize the gradle wrapper included in the source
42 | ```
43 | ./gradlew war
44 | ```
45 |
46 | The war file is compiled to: `build/libs/jersey-starterkit.war`
47 |
48 |
49 |
50 | 2) Deploy the war file to web container. I've been using apache-tomcat [http://tomcat.apache.org], and typically copy the war to the tomcat webapps directory. On my machine:
51 | ```
52 | cp build/libs/jersey-starterkit.war /usr/local/Cellar/tomcat/x.x.x/libexec/webapps/
53 | ```
54 |
55 | Shortcut: if you are using tomcat, and $CATALINA_HOME is set, you can run: `./deploy.sh`
56 |
57 |
58 | 3) Confirm that it is running by fetching the URL at on webcontainer + /jersey-helloworld/rest/hello. On my machine:
59 | ```
60 | curl localhost:8080/jersey-starterkit/rest/hello
61 | ```
62 |
63 | The supported endpoints are:
64 | ```
65 | http://localhost:8080/jersey-starterkit/rest/customer/id/1
66 | ```
67 | ```
68 | http://localhost:8080/jersey-starterkit/rest/echo?m=hello
69 | ```
70 | ```
71 | http://localhost:8080/jersey-starterkit/rest/hello
72 | ```
73 |
74 |
75 | Opening in Eclipse
76 | ==================
77 | If you use Eclipse, the gradle scripts are nice enough to create your eclipse project and classpath files.
78 |
79 | First time only
80 | ---------------
81 | If you have gradle installed, run:
82 | ```
83 | gradle eclipse
84 | ```
85 |
86 | Now you can import the project into eclipse.
87 |
88 |
89 | Updating classpath files
90 | ------------------------
91 | If you update dependencies, pull the new libs into your classpath:
92 | ```
93 | gradle eclipseClasspath
94 | ```
95 |
96 | Logging
97 | =======
98 | There is a log4j configuration defined in `src/main/resources/log4j.properties`. By default this will log to the STDOUT and to a series of log files. Change the logging configuration as needed.
99 |
100 | If you would like to use the default logging, create the logging folders:
101 | ```
102 | > sudo mkdir /restapi
103 | > chmod a+wr /restapi
104 | ````
105 |
106 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------