0

I'm using Maven from the command line on Windows, but I don't need to necessarily change the port from the command line specifically.

Running the command

mvn -Djetty.http.port=8000 exec:java

results in the following output:

[INFO] Scanning for projects...
[WARNING] The project com.google.apis-samples:oauth2-cmdline-sample:jar:1 
uses prerequisites which is only intended for maven-plugin projects but not 
for non maven-plugin projects. For such purposes you should use the maven-
enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-
rules/requireMavenVersion.html
[INFO]
[INFO] ---------------------------------------------------------------------
---
[INFO] Building Example for the OAuth2 API using JSON and OAuth 2.0 1
[INFO] -------------------------------------------------------------------- 
----
[INFO]
[INFO] >>> exec-maven-plugin:1.1:java (default-cli) > validate @ oauth2-
cmdline-sample >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.1:java (default-cli) < validate @ oauth2-
cmdline-sample <<<
[INFO]
[INFO]
[INFO] --- exec-maven-plugin:1.1:java (default-cli) @ oauth2-cmdline-sample       
---
Jun 19, 2017 5:09:53 PM 
com.google.api.client.util.store.FileDataStoreFactory 
setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody: 
C:\Users\roxlala\.store\oauth2_sample
Jun 19, 2017 5:09:53 PM 
com.google.api.client.util.store.FileDataStoreFactory 
setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: 
C:\Users\roxlala\.store\oauth2_sample
2017-06-19 17:09:53.229:INFO::Logging to STDERR via 
org.mortbay.log.StdErrLog
2017-06-19 17:09:53.229:INFO::jetty-6.1.26
2017-06-19 17:09:53.259:INFO::Started SocketConnector@localhost:1871
Please open the following address in your browser:
  https://accounts.google.com/o/oauth2/auth?client_id=<my-id>.
googleusercontent.com&redirect_uri=http: 
//localhost:1871/Callback&response_type=code&scope=https://www.googleapis. 
com/auth
/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email
Attempting to open that address in the default browser now...
Steven2163712
  • 169
  • 2
  • 12
  • What port are you talking about? – Robby Cornelissen Jun 19 '17 at 08:57
  • port for serving my app on the localhost, like localhost:8000 for example – Steven2163712 Jun 19 '17 at 09:00
  • Using what plugin? Vanilla maven does not serve applications. – Robby Cornelissen Jun 19 '17 at 09:02
  • I downloaded maven from the maven website. Then I am using the command "mvn -q exec:java" in the command line to try to look at some of Google's samples of usage of some Google APIs using Java. It says the following. I guess Jetty is the plugin that is doing the serving. 2017-06-19 17:03:41.782:INFO::jetty-6.1.26 2017-06-19 17:03:41.867:INFO::Started SocketConnector@localhost:1423 – Steven2163712 Jun 19 '17 at 09:04
  • Give `mvn -Djetty.http.port=8000 exec:java` a try. That's the standard way of specifying the port for the Jetty plugin. It is however possible that the Jetty server is governed by the application and not maven, in which case you'd have to provide more details about the application you're trying to run. – Robby Cornelissen Jun 19 '17 at 09:09
  • The app that I am trying to run is here, the oauth2-cmdline-sample. https://github.com/google/google-api-java-client-samples – Steven2163712 Jun 19 '17 at 09:17
  • Anything I should look for specifically? It has a pom.xml file. Perhaps editing that would be the solution – Steven2163712 Jun 19 '17 at 09:18
  • Looks like you're SOL. The sample instantiates the Jetty server using [`new LocalServerReceiver()`](https://github.com/google/google-api-java-client-samples/blob/master/oauth2-cmdline-sample/src/main/java/com/google/api/services/samples/oauth2/cmdline/OAuth2Sample.java), which, according to the [documentation](https://developers.google.com/api-client-library/java/google-oauth-java-client/reference/1.20.0/com/google/api/client/extensions/jetty/auth/oauth2/LocalServerReceiver) just selects an unused port. Why does it matter anyway, since you're only running samples? – Robby Cornelissen Jun 19 '17 at 09:23
  • I've tried the solutions from here, but nothing works for me. https://stackoverflow.com/questions/25644036/how-to-set-server-port-with-org-eclipse-jettyjetty-maven-plugin – Steven2163712 Jun 19 '17 at 09:23
  • It matters because I get this error. The redirect URI in the request, http://localhost:1958/Callback, does not match the ones authorized for the OAuth client. It seems that I need to know the port number that I'm going to be using when setting up my OAuth keys with the Google API – Steven2163712 Jun 19 '17 at 09:25
  • What is SOL? Couldn't find that via Google search. – Steven2163712 Jun 19 '17 at 09:26
  • 1
    Shit out of luck :) – Robby Cornelissen Jun 19 '17 at 09:26
  • Possible duplicate of [How to set server port with org.eclipse.jetty:jetty-maven-plugin?](https://stackoverflow.com/questions/25644036/how-to-set-server-port-with-org-eclipse-jettyjetty-maven-plugin) – Joe Jun 19 '17 at 09:26
  • 1
    @Joe It's not the plugin doing the serving, it's the application itself. – Robby Cornelissen Jun 19 '17 at 09:27
  • Just edit the code and change the call from `new LocalServerReceiver()` to `new LocalServerReceiver("localhost", 8000, "/Callback", null, null)` – Robby Cornelissen Jun 19 '17 at 09:32
  • Still using a random port. – Steven2163712 Jun 20 '17 at 03:55

0 Answers0