# Xpack Watcher Java API

**URL:** <https://discuss.elastic.co/t/xpack-watcher-java-api/183623>\
**Category:** Elasticsearch\
**Created:** [May 30, 2019, 10:28pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623 "2019-05-30T22:28:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aparna\_Kancharla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aparna_kancharla/32/47196_2.png) [@Aparna\_Kancharla](https://discuss.elastic.co/u/Aparna_Kancharla)\
**Post date:** [May 30, 2019, 10:28pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623/1 "2019-05-30T22:28:24Z")

</div>

Hi,

I am trying to follow the guide linked below for creating a WatchSource using WatchSourceBuilder following the instructions.

> **[Java API | Elasticsearch Guide \[6.5\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/api-java.html)**

I have setup the Maven repository and through trial and error (looking at github repositories) I have learned that this documentation is not accurate and that i will also need the following jars in my pom.xml file:

```
> <repositories>
> <repository>
> <id>elasticsearch-releases</id>
> <url>https://artifacts.elastic.co/maven</url>
> <releases>
> <enabled>true</enabled>
> </releases>
> <snapshots>
> <enabled>false</enabled>
> </snapshots>
> </repository>
> </repositories>

> <dependency>
> <groupId>org.elasticsearch.plugin</groupId>
> <artifactId>x-pack-core</artifactId>
> <version>${elasticsearch.version}</version>
> </dependency>
> 
> <dependency>
> <groupId>org.elasticsearch.plugin</groupId>
> <artifactId>x-pack-watcher</artifactId>
> <version>${elasticsearch.version}</version>
> </dependency>

```

Version i am using is 6.5.4

Following is the error i am receiving:

> [ERROR] Failed to execute goal on project : Could not resolve dependencies for project: Failure to find org.elasticsearch.plugin:x-pack-watcher:jar:6.5.4 in [http://nexus-dev/content/groups/public](http://nexus-dev/content/groups/public) was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -\> [Help 1]  
> [ERROR]  
> [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.  
> [ERROR] Re-run Maven using the -X switch to enable full debug logging.  
> [ERROR]  
> [ERROR] For more information about the errors and possible solutions, please read the following articles:  
> [ERROR] [Help 1] [DependencyResolutionException - Apache Maven - Apache Software Foundation](http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException)  
> [ERROR]  
> [ERROR] After correcting the problems, you can resume the build with the command

Note: My company does have the premium license

---

<div class="post-metadata">

**Author:** ![gose](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gose/32/37875_2.png) [@gose](https://discuss.elastic.co/u/gose)\
**Post date:** [May 31, 2019, 7:22pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623/2 "2019-05-31T19:22:07Z")

</div>

Hi Aparna,

From that doc, it looks like you need the transport dependency:

```
  <dependency>
     <groupId>org.elasticsearch.client</groupId>
     <artifactId>x-pack-transport</artifactId>
          <version>{version}</version>
  </dependency>

```

You tried that and it didn't work?

---

<div class="post-metadata">

**Author:** ![Aparna\_Kancharla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aparna_kancharla/32/47196_2.png) [@Aparna\_Kancharla](https://discuss.elastic.co/u/Aparna_Kancharla)\
**Post date:** [June 4, 2019, 8:33pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623/3 "2019-06-04T20:33:43Z")

</div>

Hi Scott,

I have tried that and it does not solve the problem.

What i have pinpointed to is that we require this jar:

```
<dependency>
  <groupId>org.elasticsearch.plugin</groupId>
  <artifactId>x-pack-watcher</artifactId>
  <version>6.5.4</version>
</dependency>

```

And I do not see the jar in the maven repository: [https://mvnrepository.com/artifact/org.elasticsearch.plugin](https://mvnrepository.com/artifact/org.elasticsearch.plugin)

Thank you,

Aparna

---

<div class="post-metadata">

**Author:** ![Mike.Barretta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike.barretta/32/16688_2.png) [@Mike.Barretta](https://discuss.elastic.co/u/Mike.Barretta)\
**Post date:** [June 6, 2019, 6:59pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623/4 "2019-06-06T18:59:03Z")

</div>

@Aparna_Kancharla

Two things:

1. Without a license, you won't have the Watcher/Alerting plugin within Elasticsearch with which your code can interact. Watcher is a commercial feature. Are you building this for use with clusters that have a license?
2. Since 5.0, the WatcherClient class is packaged in the `x-pack-transport` artifact hosted on Elastic's maven repo as described in the [Configuring X-Pack Java Clients](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-xpack-client.html) documentation. In other words, it's not in Maven central.

Ok, a third thing: the transport client is deprecated and will not support the next major version of Elasticsearch (8.0). Moving the the [high-level REST client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.1/java-rest-high.html) is recommended...it also comes packaged with the Watcher classes. We have a [migration guide](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.1/java-rest-high-level-migration.html) to help with the migration 🙂

---

<div class="post-metadata">

**Author:** ![Aparna\_Kancharla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aparna_kancharla/32/47196_2.png) [@Aparna\_Kancharla](https://discuss.elastic.co/u/Aparna_Kancharla)\
**Post date:** [June 6, 2019, 8:47pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623/5 "2019-06-06T20:47:07Z")

</div>

Hi Mike,

Thanks for the reply.

1. Yes we have the license. Yes we are building this for a cluster that has a license.
2. We actually did migrate to high-level REST client and it does have an ability to invoke POST/DELETE options but i am specifically looking to build the objects via java code. For that i was following this guide: [https://www.elastic.co/guide/en/elastic-stack-overview/6.5/api-java.html](https://www.elastic.co/guide/en/elastic-stack-overview/6.5/api-java.html)

Aparna

---

<div class="post-metadata">

**Author:** ![Mike.Barretta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike.barretta/32/16688_2.png) [@Mike.Barretta](https://discuss.elastic.co/u/Mike.Barretta)\
**Post date:** [June 7, 2019, 7:04pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623/6 "2019-06-07T19:04:37Z")

</div>

Gotcha, and apologies for reading your previous note as saying, "My company does _not_ have a premium license"

First, we no longer build the x-pack-watcher artifact, which is why you're not finding it for v6.5.4. It's been replaced by x-pack-core.

However, there might be an issue with your specific version. See [this GitHub issue](https://github.com/elastic/elasticsearch/issues/37166) detailing an bug with the x-pack-core Maven artifact. The fix was made in 6.6.1, so you'll likely need to bump up to that version, I'm afraid.

You can see all the watcher-related code in 6.6.1 [here](https://github.com/elastic/elasticsearch/tree/v6.6.1/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher)

EDIT:  
should mention that you can verify that the watcher classes are all in that x-pack-core artifact by [downloading it from our maven repo](https://artifacts.elastic.co/maven/org/elasticsearch/plugin/x-pack-core/6.6.1/x-pack-core-6.6.1.jar) and grepping the contents:

```auto
jar -tf x-pack-core-6.6.1.jar | grep -i watch

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2019, 7:04pm UTC](https://discuss.elastic.co/t/xpack-watcher-java-api/183623/7 "2019-07-05T19:04:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
