How to specify JDK in maven jetty plugin - maven

How to specify JDK in maven jetty plugin?
Like this:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven-plugin.version}</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<webApp>
<contextPath>/${project.build.finalName}</contextPath>
<jettyEnvXml>${project.basedir}/src/over/here/jetty-env.xml</jettyEnvXml>
</webApp>
<httpConnector>
<port>8080</port>
</httpConnector>
<!--<executable>${env.JAVA_IBM_HOME}/bin/javac</executable>-->
</configuration>
</plugin>
Please note: the excutable tag is incorrect, I just use it as an example.

To clarify: you actually want to specify an executable, so probably an JRE (Java Runtime Environment) and not a JDK (Java Development Kit). While it is true that JDK serve as JRE as well, this is a required clarification in my opinion.
Coming to your question, there is no such a think to specify a different JDK/JRE used to execute a certain Maven plugin: plugins are executed as part of the mvn command, which in turn is executed using the system JDK/JRE by default (set in the path) and it is actually a script which invokes a plain Java main, yes, Maven it's written in Java and its execution starts from a Java main, the following one to be clear:
org.codehaus.plexus.classworlds.launcher.Launcher#main
If you want to change the JRE used to launch this main, you need to change the JAVA_HOME variable upfront, as also explained by this old SO post.
So you would need the following:
set JAVA_HOME=path_to_your_different_jdk
mvn jetty:run
In your IDE and according to the screenshot you posted in your answer, you are actually doing the same: setting which JVM must be used.
This is true for most of the plugins, unless a specific forking mechanism is foreseen. For instance:
The Maven Surefire Plugin provides a fork mechanism via the reuseForks option and the jvm option, which also explains that:
Option to specify the jvm (or path to the java executable) to use with the forking options. For the default, the jvm will be a new instance of the same VM as the one used to run Maven.
The specified JVM (JRE or JDK used as JRE) will then be used to executed the tests (basically the same scenario you were looking for concerning the Jetty Maven Plugin.
The Maven Compiler Plugin also provides a fork option which can then use an executable option where you can effectively point at a different JDK (and not JRE in this case) to compile your code.
Sets the executable of the compiler to use when fork is true.
The Jetty Maven Plugin is executed as part of the Maven command (again, a Java main using the JRE specified by the JAVA_HOME variable or the default of your system), as also specified in its official documentation:
The classpath of the running Jetty and its deployed webapp are managed by Maven
...
For example, you might need to run your webapp in a forked instance of Jetty, rather than within the process running Maven;
And indeed a run-forked goal is provided
This goal allows you to start the webapp in a new JVM, optionally passing arguments to that new JVM. This goal supports the same configuration parameters as the jetty:run goal with a couple of extras to help configure the forked process.
This option however is mostly used to pass different arguments to Jetty rather than a different executable (for example, in case you already set the same argument for Maven and you want it with a different value for the Jetty run). So, again, the option is not there (to specify which executable/jvm to use for this forked execution). That's a pity, because they got almost there with this goal.

I think I got the answer by myself, but I still don't know how to do it in maven xml file, if you know it, please tell me.

Related

Running springboot using maven vs. via java directly?

Essentially, the Jenkins CI job runs mvn spring-boot:run .... in a productions cluster as the only way to run the application. With this build step, in effect, we are running the springboot app only via maven and this has led to a very unstable jvm behavior. Also, I am unable to configure all the possible tweaks to the jvm e.g, turning on gc logging or changing to G1GC etc.. etc..
I just wanted to know if running my java springboot app should indeed be packaged into a fat jar and run with standard jvm flags, rather than from maven.
Please let me know your thoughts
Spring boot maven plugin has jvmArguments in order to set jvm settings.
......
<configuration>
<jvmArguments>-Xdebug</jvmArguments>
</configuration>
.......
The second option is to create a self-executable jar/war and use a standard way to run app - java -jar app.jar <jvm properties>
Our teams have been running fat jars similar to how others have stated with the simple java -jar ****.jar commands. However, once in production, you can utilize a container clustering system to construct the many microservices that make up your app. Seems like running maven and deploying source code, rather than artifacts seems dangerous. Hopefully this helps!

What is the purpose of tomcat-maven-plugin?

I'm having some difficulty understanding the purpose of this plugin. Is it to modify the settings in Tomcat during the build?
I am deploying to tomcat using maven, without the plugin and it seems to work fine. Not sure if I am missing something
Cheers
Maven Tomcat plugin basically just bootstraps an embedded Tomcat container for you. Saves you the trouble of configuring an external Tomcat instance for development purposes. It can also auto-start this Tomcat instance during the build and run integration tests on it, stopping it afterwards.
If you already have a functioning workflow that you're comfortable with, no need to introduce the plugin, but it's pretty easy to configure, can run multiple web apps, can run unassembled applications etc so it's convenient to have for local development.
An even more light-weight alternative would be the Jetty plugin which starts an embedded Jetty server instead.
Maven is actually a plugin execution framework where every task is actually done by plugins.
Maven Plugins are generally used to :
create jar file
create war file
compile code files
unit testing of code
create project documentation
create project reports
A plugin generally provides a set of goals and which can be executed using following syntax:
mvn [plugin-name]:[goal-name]
For example, a Java project can be compiled with the maven-compiler-plugin's compile-goal by running following command
mvn compiler:compile
for more information go to http://www.tutorialspoint.com/maven/maven_plugins.htm
so pulgins is used to execute goals.
suppose if you don't include plugin that is required in your execution environment then it will throw an error like
A required class is missing: Lorg/apache/maven/plugin/BuildPluginManager;
so by adding appropriate plugin in pom.xml it will resolve the dependencies and execute the goal succesfully.
to remove above error just add the following plugins :
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-amps-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
</plugin>
Maven is a framework used to build JAVA applications, it provides the following
Directory Structure
Configuration Files
Build Settings
It helps in easy and structured development, primarily used for REST API Calls.
Applications built on Maven Framework, would require the same to be deployed
Its better that you get the plugin installed, since on a long run you never know what dependency may go missing
-If this helps, Mark as Answer

Maven plugin java.library.path

The maven-surefire-plugin supports using the java.library.path property by means of the <argLine> configuration option.
I need to pass the java.library.path property to sql-maven-plugin (which doesn't have an <argLine> configuration option) in order to use the jTDS driver with windows authentication (needs ntlmauth.dll).
Thanks in advance for your help.
The surefire plugin is a special case; it runs the tests in a separate JVM. Most maven plugins don't do this, they run in-process.
So you are out of luck with that plugin config.
One workaround you can try is to use the exec:exec goal of the exec-maven-plugin instead, specifying java with -Djava.library.path on the executable line and roll your own SQL-executing java code.
Otherwise, you can add -Djava.library.path to your MAVEN_OPTS environment variable, which will affect all plugins and all maven builds (which might be fine, depends on your setup), or add it every time to the mvn command line.

Specify JRockit or JDK to Maven

I'd like to know how to specify the path of JRockit libraries to Maven to use , same as we do for eclipse when you specify the JRE .
Also how do i configure maven to use Sun JDK in a project and use JRockit in another project ?
Thanks
A number of options available:
Maven uses the JAVA_HOME environment variable to determine which JVM
should run Maven (Maven is itself a Java program). I recommend this as the first option because build servers like Jenkins can easily control the JVM being used to run Maven.
You can tweak the settings of the compiler plugin to compile using
a different JDK
An alternative approach (clearer to others running your build) would
be to build in a pre-condition check into the POM, using the
enforcer plug-in. Specify a rule that the it should be compiled
using a specified Java version.

Issues with classpath running Jetty via Maven

I'm using Maven to manage my build. For developer testing I use Jetty which I launch using the jetty:run goal in the Jetty Maven plugin. I should also note that I have war:exploded running in an earlier phase which builds the directory that Jetty runs against.
The problem I'm having is that the war:exploded task puts the build dependencies into WEB-INF/lib (as it should) and furthermore, Maven appears to be feeding Jetty the build classpath via the system classloader. This leads to every jar getting loaded twice which should be OK except that, sadly, the Datanucleus library throw an exception the second time it gets loaded onto the classpath.
The only solution I can think of at the moment is to create two profiles, a build profile and a developer test profile. The developer test profile would exclude all the dependencies and jetty:run would run in the developer test profile. This seems like a lot of configuration for something I think would be simple.
Does anyone know if there is a way to prevent Maven from loading the build classpath into Jetty?
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<useTestClasspath>true</useTestClasspath>
...
The option "useTestClasspath" should have the effect you are looking for.

Resources