natsuapo
natsuapo

Reputation: 613

Failed to run java in remote command line with external jar file

I want to run my Java code in remote server with external jar file. I referred to this tutorial and run IntelliJ IDE to generate a jar file of my whole project. Now I can run the following code in local terminal successfully.

javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java
java -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try

The code will run successfully. However, when I try the same thing in server. The compile process can be finished without any errors or warnings.

javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java

I have checked that the class file new_server_try.class is generated in the directory.

However the second step will return error as Could not find or load main class new_server_try and I am not sure why this happens.

Upvotes: 0

Views: 452

Answers (1)

A Paul
A Paul

Reputation: 8251

on the second command try giving the full package name .. like shown below

java -cp "/Users/natsuapo/out/artifacts/main_jar/main.jar:lib/*" my.package.MainClass

also with operating system the command differs, check below

Windows

java -cp "Test.jar;lib/*" my.package.MainClass

Unix

java -cp "Test.jar:lib/*" my.package.MainClass

Upvotes: 1

Related Questions