Install java on linux server programmatically - java

I am trying to set up the environment with Java, git, Jenkins and maven by mentioning the IP address of linux VM. I have written a code to connect to VM, create folders, and move files to folders.
Now I want to install all Java and others software programmatically. Ib tried to install Java using yum -y install java-1.7.0. There is no error but then Java is not installed.
Please suggest what needs to be done so that Java gets installed and java_home path is set programmatically.
Any help is appreciated.

We've been doing this at the office this week. It sounds like you want a solution which would include JscH because you've started down that path. What I have to offer you is a solution that uses Jenkins.
We set up a target machine (two actually) as Jenkins slaves. It's rather easy to do, but you do need to install a JVM. You might look at docker.
Once the Jenkins slave is connected to the jenkins master, we just instruct it to run scripts. Some commands require sudo and so we set that up so that it does not require a password to be entered. Alternatively, you could run the jenkins slave jar after already having sudo -- not recommended.
We made a pom.xml to fetch .jar files and tar.gz files out of maven and copy them into a specific location. Then we executed scripts that manipulated them. The scripts came out of version control via Jenkins, but other files we pulled out of version control using a script.
All in all, I have the following tips for you:
Debug a script by executing it without Jenkins, and then run it under Jenkins for some final debug.
Put plenty of echo statements into your scripts so that you can see what has gone wrong.
You're totally relying on the Jenkins log and print debugging. This is very time consuming. So you would do well to pay attention to point #1.
Good luck :-)

Related

How to configure Jenkins, running code from Local to slave machine?

I have a project in Java and I also used Gradle and TestNG. It works perfectly without jenkins.
After that I configured Jenkins and now I can run the code with Gradle command in Jenkins on my Local.
Then I tried to run the code on Slave machine. I can see the Slave machine in Jenkins nodes. I also configured Gradle and Java to run on Slave machine. I have to mention that I don't use Version Control in this project.
When I start the job in Jenkins to run on Slave machine, it starts the job but the problem is, it cannot find for example the gradle.build, as it's located in my Local machine and not in Slave machine.
The question is, should I use Version Control? is it going to solve the problem? or should I use Copy Artifact Plugin ?
Complementary Question: If I make a local git for my network on the same machine that runs Jenkins, it is going to be a problem?
Thanks for your help :)
Slave machine need your file gradle.build, so either place it there manually by SFTP.
If your gradle.build going to change regularly then its prefer to use version control like git by which jenkins will fetch the latest files.
Again its not mandatory but recommended to use version control like git to prevent from unnecessary errors

how to create exec with installer and automatically run file

Recently I developed a jar file with JavaFX. Now my problem is how to convert it into an executable so it can install and run on other systems which do not have any JDK installed.
Also, when the client system starts from shutdown or hibernate I'd like the executable to run automatically.
I searched a lot on Google and I found content on the internet, but I did not find how I can achieve this.
how I can convert it into exec with the install so it can install into other systems which do not have any JDK on that system
You always need the JRE to run the jar file, there's no way around that. However, since the assumption that almost all systems would have the JRE installed is no longer correct, the normal thing these days is to bundle the entire JRE with the installer and use launch4j to create an exe file.
and another thing I want is that when client system start from shutdown or hibernate exec should run automatically.
You can't do this at the Java level, so it depends what OS you're running on. On windows you could use sc.exe to create a windows service from the executable, or you could just put it in the relevant user's startup folder.

Maven tests pass in Windows 10 but fail in Ubuntu 16.04

I have a Spring Boot project which passes all it's tests under the mvn clean install command in Windows 10. The same exact code base, against the same database, has some test case failures when executing mvn clean install in Ubuntu 16.04. I traced the problem to a directory not being created by the code inside a failing test case using the mkdirs() function. I don't know why, I mean, I own the project so I wouldn't think it's a permissions issue. I cloned the project in Ubuntu from the remote repository using Intellij IDEA's built in Git functionality. Many of the other test cases (hundreds of them) are passing but a few fail and they are all related to this mkdirs() issue. Just to reiterate, the problem only exists in Ubuntu 16.04, not in Windows 10 where all tests pass. If more information is needed please let me know I'll provide.
Is there any way to resolve it without altering the code?
I found that the issue was a root directory setting being set in a configuration file of the code base. While that root directory would be openly accessible on a Windows platform, on Ubuntu it was restricted. Changing the setting in the configuration file to point to a base directory where I know I had write permission solved the issue.

Jenkins hosted on Windows OS to run shell scripts after build

I am trying to run a jenkins job which has a post deployment activity of running a few shell script commands. Jenkins is hosted on a windows OS. Can anyone tell me how Jenkins can connect to the Solaris environment on another machine and execute the shell script? Is this possible?
I am trying to build a Java WAR file on windows and then deploy it on tomcat on Solaris machine.
The WAR file is built. I need to write a shell script to copy that WAR file to Solaris machine.
Does anyone know how to integrate https://wiki.jenkins-
ci.org/display/JENKINS/XShell+Plugin
I suggest you use Artifact Deployer. It can copy files to a remote location and it does support Windows.
To answer your original question, yes, Jenkins can execute shell scripts on remote hosts. The most straightforward method that comes to mind is the Jenkins SSH Plugin, or the Jenkins Publish Over SSH Plugin. Either of those plugins will allow you to execute arbitrary commands over Secure Shell (SSH) to a host that supports SSH (like Solaris).
For your specific use case, however, it may be better to use a more specialized development plugin, such as the Deploy Plugin. Especially if you're using Maven to build your project in Jenkins, Apache publishes a Maven plugin that can automate deployment to Tomcat.

using eclipse to connect to remote machine[linux server] using ssh

I am searching out for solution to use any of the IDE's such as Netbeans/ eclipse to run .jsp and .java files from a remote machine using linux as the OS. The .java and .jsp files are on the server . So, an IDE which would let me access the server and let me update the files directly on the server would be great. I use SSH terminal to connect to the server to update and get files. Now, if there was an easier way to just have an access using IDE to the linux remote machine. that would be great. Please let me know regarding the same. Thank you very much for your time.
Regards.
Your best solutions would be either to NFSmount the directory on the remote machine to your local machine. Or install something like dropbox that will sync the machines.
Is your local machine windows or linux? If it's windows, you can use WinSCP to keep the remote directory in sync with the local one. It will auto scp files when they change to the remote server.
If it's linux, I wrote a command line python script that does the same
http://pypi.python.org/pypi/scpy/
I think what you want is the Eclipse Remote System Explorer. See Ikool's Blog for more details.
like falmarri said, it's best if u can sync your files on the remote machine to your local machine. you can sync them by either using his script, or manually scp'ing or ftp'ing your files.
but my personal preference is to use mercurial or svn or other repositories. in addition to being able to sync my files, i also have access to some amazing version control of my code.

Categories