Jenkins job with multiple maven goals - java

I was assigned to maintain issues in a system created before time.
The system uses Jenkins as system integration tool and unfortunately I do not have previous experience with it.
The problem is following:
When following the steps for local build (via console) the archive files (.jars, .ear) are created correctly.
When using Jenkins job for this, one of the .jar files (call it module-one.jar) included in .ear does not contain a folder with .xsb and .class fiels.
So .ear application becomes incorrect and ClassNotFoundException is thrown.
Steps for building application locally:
cd my_project_path
cd ModuleOne
mvn xmlbeans:xmlbeans
mvn install
cd ..
mvn clean install
The Maven section in Jenkins contains only this goal clean install (the screenshot below section "Build"):
So what I wonder is how to add the following maven tasks in Jenkins job to be executed on ModuleOne:
mvn xmlbeans:xmlbeans
mvn install
My idea is to go to "Pre Steps" section and add following maven goal:
mvn xmlbeans:xmlbeans install
My questions are:
1. If I am on the right way how to define the goal "mvn xmlbeans:xmlbeans install" to be executed exactly on ModuleOne?
2. If I am not on the right way are there at all any solutions to do this with Jenkins?
Here is screenshot with my suggestion for "Pre Steps". In the current configuration (that skips to add proper dirctory with .xsb and .class fiels to ModuleOne) this section is missing, but the section "Build" is as it is used now.

I think your approach is good! But on "pre steps":
Remove "mvn" from Goals
Use Advanced configuration in order to specify the path of your pom.xml

Related

mvn cli with chosen plugins location

Is there a way to make maven use another repository than the configured one on CLI?
Eg.: maven is using the org.apache.maven.plugins:maven-clean-plugin:3.2.0 jar maven-clean-plugin-3.2.0.jar in the configured maven repo. I’d like to make maven run mvn clean with this jar from another location on the disk, like –
> mvn clean -<some-option> <maven-clean-plugin-3.2.0.jar-location-of-choice>
I looked up the command line options, nothing directly saying it so far
TIA

Want to build project with commandline mvn but have to use Maven update in eclipse first

I'm working with multiple projects in Eclipse. because I want to automate the building I want to script the building process.
Unfortunately I cannot do the same actions on the commandline as in Eclipse.
So a common problem is that when a new function from a referenced project is used, I cannot build the project on the commandline with mvn. I use the command:
mvn clean install -U
But this command will give a build failure until I do a Eclipse Maven Update from the eclipse GUI. After that I can build the project again.
I also tried all the other commands I came across Stackoverflow:
mvn eclipse:eclipse
mvn dependency:resolve
So I just want to that Maven Update command in eclipse from the commandline so I can build from the commandline. If anyone could tell me what I'm doing wrong that would be awesome.
Thx in advance
Update for more clarification:
The project structure is:
Rest-service, Framework-service, Framework-model
Framework-model is referenced in the pom file by Framework-service and Framework-service is referenced by Rest-service. The other projects are not relevant to the problem.
When a function is added to Framework-model and used in Rest-service it gives an compilation error in eclipse and when I build with mvn clean install -U, although Maven install in eclipse is succesful but I think it is still using the old compiled code. After a Maven Update command in eclipse the compilation error is gone. And mvn clean install -U from the commandline also works.
How could I do a Maven Update command in the commandline? If mvn clean install -U should also do a Maven Update command, what settings should I check?
Another update: So this weekend I tried different things and running mvn compile before the mvn clean install -U command gives a different output. And finds the new function. But as I read maven, I thought install should also do the previous steps. How is this possible?
Eclipse's Maven plugin uses the maven version configured in Preferences/Maven/User settings. If you have a different version of maven in your Eclipse's settings than the one on your PATH variable, you could have different outputs. Maybe try and check that.

a method to build an executable JavaFX Jar from Maven Archetype

I want to be set an archetype for a stable JavaFX (Java 8) Maven build that will produce an executable JAR that (always) runs from the command line. And preferable without needing to build an UberJar or similar.
When we use the Netbeans 'Maven JavaFX' archetype the resultant JAR file following a build runs. As a project grows we find that sometimes the JAR won't run from the command line. Some Maven POM edits have been needed to 'encourage' the program to run from the command line again. This applies to Linux and Windows.
This also happens directly with the ZenJava JavaFX archetype, e.g. a project artifactId=xx:
java -jar target\xx.jar
no main manifest attribute, in target\xx.jar
This is just from the mavan generate command. The details of the two archetypes in question are:
zenjava
archetypeArtifactId=javafx-basic-archetype
archetypeGroupId=com.zenjava
netbeans
archetypeArtifactId=javafx
archetypeGroupId=org.codehaus.mojo.archetypes
Comparing the resulting POM files shows these that the codehaus.mojo (netbeans) uses these plugins in the build:
maven-dependency-plugin
maven-compiler-plugin
exec-maven-plugin
Either project runs happily from within Netbeans IDE. The challenges occur when we want to test on command line. It isn't really the best look externally when the build looks unstable to outsiders like that.
The questions arising are about what are the requirements to make a JavaFX command-line executable JAR file? For JDK 8 and beyond.
Is there an alternative JavaFX archetype available that will build projects with dependent JAR-s and run from the command line?
What allows Netbeans (say) to execute JAR when the same the built JAR won't run on the command-line?
What 'magic' does Netbeans be add to the execute step?
What is needed for the zenjava archetype to run "Java -jar"?
The JAR resulting from the follow steps doesn't run on the console.
mvn archetype:generate -DarchetypeGroupId=com.zenjava -DarchetypeArtifactId=javafx-basic-archetype ... -DartifactId=xx
mvn install
java -jar target/xx-001.jar
What influences the: maven-dependency-plugin and maven-compiler-plugin when building the JAR for bigger projects?
In other words, what assumptions might be being broken a project grows and bind with other JAR files.
Needless to say, the Maven generate and build steps are using the JDK Java environment. The execution though, java -jar target/xx-001.jar, need to run under the simple JRE (without the JDK). I guess question #4 is a long stretch unless you are someone who has a biggish JavaFX project and solved this already. Suggestions welcome.
just to mention: I'm the maintainer of the javafx-maven-plugin (and the archetype).
To answer your question 3:
You have to call the GENERATED jar-file from the plugin, which is located at target/jfx/app/yourapp.jar
The generated jar-file will reference all required dependencies, which are noted inside the META-INF/MANIFEST.MF-file inside it. While creating that jar-file, the pom is scanned for runtime-dependencies, these will be placed at the target/jfx/app/lib-folder. When bundling your app into native bundle, the JRE is put aside of the generated launcher under the target/jfx/native/-folder.
What confuses me about your problem: mixing CLI- and GUI-application might result in problems, but i guess it's just your special requirement :)
EDIT:
Calling mvn install does NOT generate jfx-jar without special configuration, you have to call mvn jfx:jar or mvn jfx:native to call the MOJOs of the plugin. For easier configuration, please visit our configuration-website: http://javafx-maven-plugin.github.io/

Java project runs in IDE (IntelliJ Idea) but fails to run after Maven build

I have a Java project that is ready to ship, but i have stumbled at the last hurdle. The program runs fine in the IDE, but after i run mvn clean install and the target jar is created successfully, the application fails both on the command line AND in the IDE. I can get it to run again in the IDE by doing a rebuild from within the IDE.
Has anyone else experienced something similar?
The error after the mvn clean install is
2014-08-08_10:38:20.328 INFO coza.modh.fxplatform.Controller - Application start
2014-08-08_10:38:20.344 INFO c.m.f.c.p.DataSourceFactory - Connecting to Database.
2014-08-08_10:38:20.499 INFO coza.modh.fxplatform.Controller - Model created
Exception in thread "main" java.lang.NullPointerException
at coza.modh.fxplatform.view.MainView.<init>(MainView.java:46)
at coza.modh.fxplatform.Controller.startup(Controller.java:40)
at coza.modh.fxplatform.Application.main(Application.java:7)
The line it fails on looks like this:
setContentPane(contentPane);
If i rebuild from within the IDE then the variable is not null when it gets here, but after the mvn command the variable is null when it gets to this point.
EDIT: Someone pointed out that it might be related to the fact that i used the intelliJ GUI designer tools and that Maven might not gel with it. Possibility?
I had a similar problem today. To solve the issue -
Firstly, add the following to the pom.xml
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>5.0</version>
</dependency>
Secondly, as you stated, use the correct maven plugin to create the build.
See this for step by step instruction.
Unlikely that contentPane is null, but check. Do a clean build anyway. Maybe the line number is not entirely correct.
Normally the problem are resources, like an application icon.
They are not File but zipped inside the jar.
So paths like /src/main/resources/... will not do.
Neiter using a backslash \, and
furthermore the file paths are case sensitive.
This can be caused by different library versions, do you have changed the build path in Eclipse? (Project->Properties->Build Path -> Libraries). There should only be "JRE System Library". If there is more, then it is possible that it is be loaded instead of one of your Maven dependencies. You using "mvn clean install" means it is compiled against the Maven dependencies and thus it runs differently.
Install Maven on the system(not having IDE) before running the code
ensure you've got system property M2_HOME set to your Maven installation location and also Maven bin folder added to PATH
go to the directory,containing pom.xml of your project and type "mvn install" plus Enter to build your project
if it's for example simple project,packaged as JAR,you can run it then by typing something like this in the console:
$ java -cp target/simple-1.0-SNAPSHOT.jar org.yourcompany.projectNam.App
and Enter

Write custom maven command set using eclipse plugin

from command line I can write
mvn install -Pauto-deploy
Is it possible to store this command in my eclipse maven plugin. I want to execute this command by click.
I see only standart things in maven menu:
build
clean
install
test
I want see at this list my_autodeploy_command
I am sure it is possible but I don't know how.
Can you show how?
where can I write mvn install -Pauto-deploy ?
Somewhere here?
UPDDATE
for taringamberini
The dialog is the correct one. Install, the lifecycle phase to run up to, is put into the goals field, your profile (auto-deploy) is put into the Profiles field (without -P):
You could also copy the full line (without leading "mvn") into the Goals field
Is it possible to store this command in my eclipse maven plugin.
Yes, it is:
In the Package Explorer view right click your Maven project
choose Run as and Run configurations...
right click on Maven Build (node added by your eclipse maven plugin) and choose New
Compile the filed Name for example with clean_test_install
Compile the field Base directory browsing your maven project directory
Compile the field Goals for example with clean build test install
click Apply and close the Run Configuration window
Now, in the tool bar, if you click on the drop down menu at the right of the Run As ... button you can see the clean_test_install entry.
UPDATE
You can do it in maven plugin in eclipse as below.
Go to debug configuration eclipse --> New configuration in Maven Build
Specify Goals as clean -install and select base directory as project which you want to build. You can also skip test if we want in configuration
I had an ugly/complicated maven command which launched my project. And On Windows, I wanted to launch it in eclipse - to see the console, and not under a command prompt - where you can't see the console clear. The Maven command was something like:
mvn -am -pl web package -DskipTests -P link-repo,tomcat-run,local-jive -Dfile.encoding=UTF8
So blackbuild answer:
"You could also copy the full line (without leading "mvn") into the Goals field"
saved my life!
I just copied the maven command in Goals field and it worked!

Categories

Resources