Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX 10.13.6: Error: Could not find or load main class #69

Closed
jmrodriguez opened this issue Aug 20, 2018 · 3 comments
Closed

OSX 10.13.6: Error: Could not find or load main class #69

jmrodriguez opened this issue Aug 20, 2018 · 3 comments

Comments

@jmrodriguez
Copy link

After adding and configuring the plugin, when trying to run the project containing it, we get the next error:

[INFO] Using Elasticsearch [0] configuration: com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration@2bef09c0[id=0,baseDir=/myproject/target/elasticsearch0,httpPort=9200,transportPort=9300,pathData=<null>,pathLogs=<null>,settings=<null>]
[INFO] Elasticsearch[0]: Executing command '[chmod, 755, bin/elasticsearch-plugin]' in directory '/myproject/target/elasticsearch0'
[INFO] Elasticsearch[0]: The process finished with exit code 0
[INFO] Elasticsearch[0]: Executing command '[sed, -i, -e, 1s:.*:#!/usr/bin/env bash:, bin/elasticsearch-plugin]' in directory '/myproject/target/elasticsearch0'
[INFO] Elasticsearch[0]: The process finished with exit code 0
[INFO] Elasticsearch[0]: Executing command '[bin/elasticsearch-plugin, list]' in directory '/myproject/target/elasticsearch0'
[INFO] Elasticsearch[0]: The process finished with exit code 0
[INFO] Elasticsearch[0]: Executing command '[chmod, 755, bin/elasticsearch]' in directory '/myproject/target/elasticsearch0'
[INFO] Elasticsearch[0]: The process finished with exit code 0
[INFO] Elasticsearch[0]: Executing command '[sed, -i, -e, 1s:.*:#!/usr/bin/env bash:, bin/elasticsearch]' in directory '/myproject/target/elasticsearch0'
[INFO] Elasticsearch[0]: The process finished with exit code 0
[INFO] Elasticsearch[0]: Executing command '[bin/elasticsearch, -p, pid, -Ecluster.name=esDevCluster, -Ehttp.port=9200, -Etransport.tcp.port=9300, -Ehttp.cors.enabled=true]' in directory '/myproject/target/elasticsearch0'
Error: Could not find or load main class -Xms500m
Exception in thread "Thread-5" java.lang.IllegalStateException: This Elasticsearch process destroyer does not support this operation
	at com.github.alexcojocaru.mojo.elasticsearch.v2.ForkedElasticsearchProcessDestroyer.remove(ForkedElasticsearchProcessDestroyer.java:50)
	at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:411)
	at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
	at com.github.alexcojocaru.mojo.elasticsearch.v2.util.ProcessUtil.executeScript(ProcessUtil.java:222)
	at com.github.alexcojocaru.mojo.elasticsearch.v2.util.ProcessUtil.executeScript(ProcessUtil.java:167)
	at com.github.alexcojocaru.mojo.elasticsearch.v2.ForkedInstance.run(ForkedInstance.java:42)
	at java.lang.Thread.run(Thread.java:748)

After adding a few debugging messages to the elasticsearch run script and running it directly, we noticed that the final java command is like the next one

/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/java -Xms2G -Xmx2G -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/myproject/target/elasticsearch0 -cp /myproject/target/elasticsearch0/lib/* org.elasticsearch.bootstrap.Elasticsearch

Running the previous command directly yields to the exact same error.

However, quoting the -cp parameter value makes it work just fine, like this

/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/java -Xms2G -Xmx2G -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/myproject/target/elasticsearch0 -cp '/myproject/target/elasticsearch0/lib/*' org.elasticsearch.bootstrap.Elasticsearch

Kind Regards
Juan

@alexcojocaru
Copy link
Owner

It appears that the issue you are describing is in the bin/elasticsearch shell script. The plugin starts a new process using the arguments listed on the last INFO line in your output (ie. the last [INFO] Elasticsearch[0]: Executing command ...). From here on the ES startup script takes over and builds the java command to execute.

Off the top, I would suggest one of the following:

  • download the ES distribution, unzip and start ES; or simply go to ${your_mvn_proj}/target/elasticsearch0 (this is where the ES distro gets downloaded and unpacked by the plugin) and run $ bin/elasticsearch; I would expect this to fail as well
  • upgrade the ES version in the plugin config; I just checked the bin/elasticsearch in 5.0.0 and it uses this to execute java (note the double quotes around the cp): $ exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" org.elasticsearch.bootstrap.Elasticsearch "$@"

You didn't say what the plugin config is. I am interested in the plugin version and the ES version.

@jmrodriguez
Copy link
Author

Here's the full plugin config

          <plugin>
            <groupId>com.github.alexcojocaru</groupId>
            <artifactId>elasticsearch-maven-plugin</artifactId>
            <version>${maven.plugin.elasticsearch.version}</version>
            <configuration>
              <clusterName>esDevCluster</clusterName>
              <httpPort>${es.httpPort}</httpPort>
              <transportPort>${es.tcpPort}</transportPort>
              <version>${maven.plugin.elasticsearch.configuration.version}</version>
              <keepExistingData>true</keepExistingData>
              <timeout>60</timeout>
              <skip>${es.skip.start}</skip>
              <pathConf>elasticsearch/conf</pathConf>
              <logLevel>DEBUG</logLevel>
            </configuration>
            <executions>
              <execution>
                <id>start-elasticsearch</id>
                <phase>validate</phase>
                <goals>
                  <goal>runforked</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-elasticsearch</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

where

<maven.plugin.elasticsearch.version>6.4</maven.plugin.elasticsearch.version>
<maven.plugin.elasticsearch.configuration.version>5.6.8</maven.plugin.elasticsearch.configuration.version>

As you mentioned in your comment, running bin/elastic throws the exact same error.

I tried editing the bin/elasticsearch script to add quotes to the -cp parameter, but when I run the project with the respective mvn command, the target/elasticsearch0/bin/elasticsearch script is re-generated by the mvn process, so any changes I do are overwritten.

I might have found a workaround for the issue though.

If I set the ES_JVM_OPTIONS env variable to -cp "./target/elasticsearch0/lib/*" in my IDE's (IntelliJ) run configuration (or in the terminal before executing the run command), the project runs nicely, but took quite some time to figure that out.

Perhaps worth adding that to the README file for other OSX users?

@alexcojocaru
Copy link
Owner

Thanks for the additional details and for describing the workaround. I will add a note about this to the README.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants