Forum Stats

  • 3,727,632 Users
  • 2,245,422 Discussions
  • 7,852,901 Comments

Discussions

Newbie question about Java, modules/libraries and dependencies.

pmu
pmu Member Posts: 3
edited February 2018 in New To Java

Foremost apologies for asking a noob question.  I have no experience with Java, but have written some scripts in Perl and Python before (more in Perl than in Python).

The script would SSH into storage devices, gather outputs and email them out to the monitoring/alerting team's email address. While this works fine, here are some issues that are compelling me to look at a different language.

1) Along with Perl, the SSH Module, Email Modules were required to be installed on the servers from which the scripts would run. So, I would write the scripts on my laptop (which has Perl + the required modules installed) and test it. After that, I would need to copy the script to the Server from which it's supposed to run. But just copying the script would not help. I would have to install the modules on the server as well, and many times, due to security reasons, it's not allowed.

2) The script had to be run by a scheduler. I would rather the script get executed once the failure / issue occurs on servers.

Using Java, can I create a single executable, which when copied on to a server will run all by itself, meaning without copying the SSH or Email modules? Ofcourse, I will have to install the required modules for (SSH/Email etc.) along with java and javac on my laptop, but once I do that, write the java program and compile it, can I move the compiled binary on a different server, run it from there and it will run without requiring to install any modules?

Can I do some Event based programming with Java?

Sorry once again for my noobish question.

Regards,

pmu

pmumNem

Best Answer

  • Unknown
    edited February 2018 Accepted Answer
    Using Java, can I create a single executable, which when copied on to a server will run all by itself, meaning without copying the SSH or Email modules? 

    No - an app that uses third-party modules/jars/other needs those same modules/jars/other where ever it is going to be executed.

    Java does NOT bundle everything together into an EXE/DDL/SO file that you can just execute anywhere.

    If you want mail/other services on a server then you need to install and configure them on that server.

    pmupmu

Answers

  • Unknown
    edited February 2018 Accepted Answer
    Using Java, can I create a single executable, which when copied on to a server will run all by itself, meaning without copying the SSH or Email modules? 

    No - an app that uses third-party modules/jars/other needs those same modules/jars/other where ever it is going to be executed.

    Java does NOT bundle everything together into an EXE/DDL/SO file that you can just execute anywhere.

    If you want mail/other services on a server then you need to install and configure them on that server.

    pmupmu
  • mNem
    mNem Member Posts: 1,380 Gold Trophy
    edited February 2018

    Here are some links to start off... (copied from Java tutorial site)

    • Getting Started — An introduction to Java technology and lessons on installing Java development software and using it to create a simple program.
    • Learning the Java Language — Lessons describing the essential concepts and features of the Java Programming Language.
    • Essential Java Classes — Lessons on exceptions, basic input/output, concurrency, regular expressions, and the platform environment.

    Once you overcome the initial hurdles of writing a Java program, you may find the following links useful:

    1.

    Java - Add Email Subject and Body (a somewhat similar task to yours, though without the ssh)

    2.

    https://javaee.github.io/javamail/FAQ

    3.

    https://stackoverflow.com/questions/995944/ssh-library-for-java

    pmupmu
  • pmu
    pmu Member Posts: 3
    edited February 2018

    Hi rp0428,

    Thank you for the clarification.

  • pmu
    pmu Member Posts: 3
    edited February 2018

    Hi mNem,

    Thanks for the links.

    I had tried doing some automation in Python, but just could not seem to wrap my head around the whitespaces and some of the concepts.

    I really missed the curly brackets, and some other stuff that's there in Perl but not in Python.

    The great thing about Java is the details in which it expects stuff.

    I've already picked up a book, "Java A Beginner's Guide" by Herbert Schildt for Java version 8. I will also refer to the links you have given. Thank you once again.

    mNem
This discussion has been closed.