Is there a way to run java code when executing "Maven Deploy"? - java

I have been given the task of developing code that generates an email when a user deploys new code to our servers. I already have the code to generate the email. However Im trying to run this code when we add new code to our servers. We currently deploy new code to our servers using the MAVEN Deploy command in Eclipse. I was wondering if there is a way to run a java main method or something along those lines when a user selects Maven Deploy in Eclipse?

Not sure of your actual use case or if this is the best approach, but you can run java programs using the maven exec plugin. See here for more details: http://www.mojohaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html

Related

Unable to run Rhapsody application via Jenkins

when we run a Rhapsody application via Jenkins.
My scenario:
1) I need to get details about various diagrams in a Rhapsody model.
2) I have written Java code using api provided by Rhapsody to get the details of various diagrams.
3) this java code is made into Jar and is run via command line, works fine by invoking Rhapsody in background.
4) when this same command is put in jenkins to run as windows command, the job fails,
The code is able to connect to Rhapsody Instance, but somehow unable to open a project.
Did anyone resolve this type of issue ??
Yes I faced this issue when running a plugin in jenkins where I was not able to open the rhapsody instance as it was throwing an examption.
To solve make user which runs the jenkins job has the license for rhapsody if yes try to open your rhapsody project manually and run the script from the job.
Hope these solution works for you

How to query Jenkins using java

I am programming using java to fetch few information from Jenkins url. I am trying to get information on nodes, projects created etc. All these are get commands. On browsing about it, I reached following link:
http://javadoc.jenkins.io/
I tried using import statement "import hudson.cli.GetNodeCommand;". But it is throwing me error : The import hudson.cli.GetNodeCommand cannot be resolved.
I have imported jars from my JEnkins url ( https://jenkins.example.com/jnlpJars/jenkins-cli.jar). How do I resolve this? I downloaded this jar from github also and that also has same structure as in the screen shot below. There is no GetNodeCommand class inside 'hudson.cli' package. How do I fetch information about nodes?
The class hudson.cli.GetNodeCommand is part of Jenkins core, and not part of the CLI client JAR. See the developer documentation for pointers to building Jenkins itself, if you want to do something with these classes.
If you want to execute GetNodeCommand, you can do so by running the CLI client with the get-node command, e.g.: java -jar jenkins-cli.jar get-node node-name.
A list of all CLI commands available in a given Jenkins installation can be found at https://<jenkins-host>/cli/.
If you want to fetch information not available via the provided CLI commands, the standard way to do so is the Script Console, which enables you to write Groovy to access the Jenkins APIs. This functionality is also exposed through the CLI via the groovy command.

How to auto reload app engine dev server?

Im following the tutorial on the App Engine website for 'Google Cloud Endpoints' in Java. Everything works fine and I can run the development server using mvn appengine:devserver. The problem is that when I make any changes to a file (for example, any java file) the dev server doesnt automatically recompile. I need to ctrl-c to kill the dev server and restart it for every code change I make.
Is there a way to have maven automatically detect changes to any files in my project and have it automatically rebuild and restart the dev server?
Unfortunately no. If you want this behavior on your dev server, you need to use Python.
I run in the same issue and there is no real workaround provided by the App Engine to help you doing this.
From the "Using The Google plugin for Eclipse":
With Eclipse, you can leave the server running in the debugger while you make changes to source code, JSPs, static files and appengine-web.xml. When you save changes to source code, Eclipse compiles the class automatically, then attempts to insert it into the running web server dynamically. In most cases, you can simply reload the page in your browser to test the new version of the code. Changes to JSPs, static files and appengine-web.xml are recognized by the development server automatically, and also take effect without restarting the server. If you change web.xml or other configuration files, you must stop and start the server for the changes to take effect.
(https://developers.google.com/appengine/docs/java/tools/eclipse#Running_the_Project)
There is NOTHING comparable in Java (link from "The Java Development Server") (https://developers.google.com/appengine/docs/java/tools/devserver)
There's currently nothing in the App Engine SDK to automatically restart when files change, but that's not to say you can't do it. I ran into the same problem and wrote up a script to listen for file changes as triggers to restart App Engine. It's in JavaScript, so you'll need to install Node.js if you haven't already.
// Install watch-exec
$ npm install -g watch-exec
// Watch the current directory
$ watch-exec --command "mvn appengine:devserver" --watch .
This will immediately start App Engine, and then restart it any time a file changes. If the app crashes for some reason, the script will wait for your next edit before trying to restart.
P.S. That entire script is about 40 lines of code, and you could probably do the same thing in other scripting languages. If you haven't tried writing your own automation before, I'd definitely recommend checking out the source code to see how this works.
I've found using Gradle, GAE, and Spring MVC, the assemble command will put the correct artifacts in place, and the server will re-init the app. It's a little quicker than a server restart.
Using App Engine standard with the cloud.tools appengine-maven-plugin hot swap works fine (most of the time, can be problems when setting up the workspace).
For a multi-module maven project: no need to stop the server or browser,
just push the code changes (maven command package -pl *-server)
& refresh the browser.
Debugging with a debug client currently works perfectly for changing / adding code within methods.

How to display changes in web browser when Building a RESTful Web Service using Spring?

I am following this tutorial:
https://spring.io/guides/gs/rest-service/
After completing the tutorial I run everything in my web browser on my local host and everything seems to work.However when I make changes in the java code (I made errors on purpose) I can still run everything in the web browser. What do I need to do in order for it to change due to my code changes? I guess I should mention that I am using eclipse and have installed maven as a plugin.
You are changing the source code, but not the compiled files. Your service is using the created "gs-rest-service-0.1.0.jar" file. This is not affected by your code changes.
Jump into the tutorial again where it says:
"Build an executable JAR"
This will rebuild your jar file. Afterwards you will have to restart your service like you did in the chapter "Run the service".
Instead of using maven as a plugin a choose to install it in order to use the command prompt.

How to open and run a specific script from the command line in eclipse

I am trying to run an automated suite every day at the same time, so I want to create a task to open eclipse and execute the main script every day. Is there a way to do this from the command line?
Instead of using eclipse for it, use a software that is dedicated for it - continous integration servers are created for it. Check such titles like: hudson, cruiseControl, TeamCity
You are on the wrong path. Instead of trying to automate opening eclipse, executing a main... break the IDE dependency, write a portable build script using Ant or Maven and execute that build script outside the IDE (using a simple cron job or something more elaborated like a Continuous Integration tool but I'm not sure you need a CI tool for now, start with the build script).
So I am assuming that you want to automate something that you run from inside eclipse. if it's a build then I'm with the other guys that using a build script and CI is the way to go.
But in case it's not that use case...
Now, if you are using the "Run.." dialogs to do this you can actually get the command line paths, binaries and arguments that eclipse used to execute.
What you do is open up the debug perspective. Then run your script however you normally do.
Your Process should appear in the "Debug View" at this point.
Either while the process is running or after termination, right click on the process and open up the properties. (you may need to click 1 level down in the tree to get this option)
Under process info, inside of that there is a section "Command Line". This is the exact command line that eclipse executed behind the scenes to run.
you should be able to put this into a script (.bat for windows / sh for *nix) and schedule accordingly.
edit: added in assumptions, changed to use process info terms which is what is on the properties screen.

Categories

Resources