I need to use maven with a settings file in a specific location, normally you can give MAVEN_OPTS env variable but they are passed to JVM so the following will yield:
$ MAVEN_OPTS="-s /settings.xml"
$ mvn clean
Unrecognized option: -s
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
I searched a lot but found two keys, org.apache.maven.user-settings and org.apache.maven.global-settings which is explained here but it seemed it was working with Maven 2 only. Aliasing mvn to mvn -s /settings.xml would probably work but I do not like it.
From the mvn shell script:
# -----------------------------------------------------------------------------
# Apache Maven Startup Script
#
# Environment Variable Prerequisites
#
# JAVA_HOME Must point at your Java Development Kit installation.
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
# -----------------------------------------------------------------------------
so MAVEN_OPTS contains JVM arguments, not Maven arguments (which is consistent with the error message indicating the JVM doesn't like your arguments).
The actual invocation is
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dmaven.home=${MAVEN_HOME}" \
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$#"
so there is nowhere to put it. I would therefore suggest that you write your own ? mvn script which in turn calls the real maven command with the arguments you like (in my experience scripts are more robust than aliases). Additionally I have recently found myself that the Java versions later than 8 have ... interesting issues... so I really need to have mvn8, mvn11 (and perhaps more) commands anyway.
Another approach that I only started using recently is the Maven wrapper (https://github.com/takari/maven-wrapper) where a ./mvnw command is placed in your project which then downloads Maven when needed. This is very useful. To get started use
mvn -N io.takari:maven:wrapper
after which ./mvnw should be directly usable instead of mvn. The interesting part here is that the generated Maven command looks like
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$#"
and MAVEN_CONFIG is not set earlier in the script. So for mvnw you can set MAVEN_CONFIG to your "-s /settings.xml" string.
Maven 4
The MAVEN_ARGS environment variable is supported and can be used.
Maven 3
There was a feature request MNG-5824: Support MAVEN_ARGS environment variable as a way of supplying default command line arguments. This was closed unimplemented with a suggestion to use the .mvn/maven.config in project directory
Related
I deployed a Python project on Google App Engine. As the project has a dependency on Java, I used a Docker container configuring two environments: Python + Java.
However, when I make a call to my Python service in GAE it's getting "java command is not found from this Python process. Please ensure Java is installed and PATH is set for java" error.
During the build process of the Docker file I am able to access Java after installing it. But during API execution it is not recognized by Python.
The "app.yaml" file used:
runtime: custom
env: flex
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker src.main:app
Below are the the Docker file used in Deploy:
### 1. Get Linux
FROM alpine:3.7
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
### 2. Get Java via the package manager
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
#### OPTIONAL : 4. SET JAVA_HOME environment variable, uncomment the line below if you need it
ENV JAVA_HOME="/usr/lib/jvm/java-1.8-openjdk"
RUN export JAVA_HOME
ENV PATH $PATH:$JAVA_HOME/bin
RUN export PATH
RUN find / -name "java"
RUN java -version
FROM python:3.7
EXPOSE 8080
ENV APP_HOME /src
WORKDIR /src
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
COPY . /src
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080"]
Here is a printout of the RUN java -version command during the deploy process:
RUN java -version command
Does anyone know why the error is happening even with Python and Java running on the same service on App Engine?
Are there any additional settings missing?
You are using two FROM in a Dockerfile, so you're effectively doing a multi-stage Docker build, but you are doing it wrong.
A multi-stage build should be something like this:
### 1. Get Linux
FROM alpine:3.7 as build
# here you install with apk and build your Java program
FROM python:3.7
EXPOSE 8080
...
# here you copy what you need from the previous Docker build, though
# since it was Java, which is not installed here anymore because it is
# a python image, you need to consider if you really need a multi-stage
# build
COPY --from=builder /src /src
Otherwise, just remove the second FROM python:3.7 and install it with apk.
I was hoping JMC would be available with OpenJDK, JDK11 binaries as this has been opensourced from Java 11 by oracle, but could not locate this in Oracle and AdoptOpenJDK Java-11 binaries under bin folder.
I have also tried this https://jdk.java.net/jmc/ as some article said its being releases separately.
Does anyone know how to get JMC for OpenJDK-11.
I am editing this answer since builds are now available, and have been available, from multiple vendors for quite some time. The list is available in the readme for the JMC GitHub repo:
https://github.com/openjdk/jmc
Don't forget to give the project a star if you like it! :)
Here is the original answer:
Normally the builds will be available here:
https://jdk.java.net/jmc/
See http://hirt.se/blog/?p=1007 for more information on the new delivery format.
The builds have been (temporarily) pulled because a switch from the old javax.mail coordinates to the new coordinates at jakarta-ee has not yet gotten the proper third-party approval. A new build, with plenty of fixes and with all the approvals properly in place (or a revert of the change), should be along within the next few weeks.
Up until then it is possible (also not hard) to build JMC 7, by pulling the official JMC repo from here:
https://hg.openjdk.java.net/jmc/jmc7/
You can also build and pull the mainline mirror from the inofficial GitHub repo:
https://github.com/JDKMissionControl/jmc
For more information on building JMC, see:
http://hirt.se/blog/?p=947 (or simply read the README.md in the repository root)
Good luck!
Since Java11, JMC is not part of the JDK any more. It is a separate project, as you already noticed.
https://www.oracle.com/technetwork/java/javase/11-relnote-issues-5012449.html
Azul provides free, unsupported builds of Zulu Mission Control available for download at http://azul.com/products/zulu-mission-control
Builds are available for clients running Windows, Linux, and Mac OS X.
There are now binaries produced by Oracle as well:
https://jdk.java.net/jmc/
I believe they're still evaluating GitHub to moving to an independent repository with current progress being still under jmc7.
You can currently download standalone versions from Oracle's website for mission-control.
BellSoft provides Liberica Mission Control: https://bell-sw.com/pages/lmc/
As per their documentation, it's free to use in production environments, and there is a commercial support included as part of Support Subscription for Liberica JDK.
Update
JMC 8 available when compiling it from source. Here is a single command for linux users to build your own copy of jmc
mkdir ~/jmcToDelete && \
cd ~/jmcToDelete && \
git clone https://github.com/openjdk/jmc.git && \
cd jmc/releng/third-party && \
mvn p2:site && \
runJetty="mvn jetty:run" && \
bash -c "$runJetty &" && \
cd ~/jmcToDelete/jmc/core && \
mvn clean install && \
cd ~/jmcToDelete/jmc && \
mvn package -Dmaven.test.skip=true && \
kill $(jps | grep Launcher | awk '{print $1}') && \
sudo mkdir -p /opt/java/jmc && \
sudo tar xzf $(find ~/jmcToDelete/jmc/target -name '*.jmc-linux*') -C /opt/java/jmc && \
sudo ln -s /opt/java/jmc/jmc /usr/local/bin/jmc && \
rm -rf ~/jmcToDelete
typing jmc in a terminal should start it.
Outdated
As stated by Hirt you can compile it from http://hg.openjdk.java.net/jmc
The jmc available in jdk8 (v5.5) requires the special flags -XX:+UnlockCommercialFeatures -XX:+FlightRecorder to be present in the JVM process and it will not retrieve "flight records" if they are not there, so you can only use it with java1.8. If you would like to add those flags on openjdk-11 it will fail with Unrecognized VM option 'UnlockCommercialFeatures' meaning that you don't need them as they are enabled by default ( FlightRecorder ).
I compiled jmc-7.1.0 without issues by downloading the gz archive from http://hg.openjdk.java.net/jmc/jmc/
Follow the steps present in the README file:
Make sure the compilation is done with jdk1.8
In one terminal :
cd releng/third-party
mvn p2:site
mvn jetty:run
And in the second terminal:
cd core
mvn clean install
cd ..
mvn package
On completion you should have all your artefacts in the target folder.
The default jmc start script has a lot of flags present and it will not start with all of them, hence you can start the intended jar using
java -jar ./jmc-[...]/target/products/jmc/plugins/org.eclipse.equinox.launcher_[...].jar
When I use mvn spring-boot:run to run a Spring Boot project, I find if use the command in Cmd, it works. but if I use it in Git Bash, it can't work.
So I use java -version and mvn -v to view the Java and maven version.
java -version give me the same result, but mvn -v result is different, as the picture shows:
And when I see my java path, I'm sure it's C:\Program Files\Java\jdk1.8.0_151
So I want to know, why there are two Java paths in my PC when I use mvn -v?
Both the java executable and Maven by default use the JDK that is specified in the $JAVA_HOME environment variable.
You are executing java and Maven (mvn) in different environments (cmd.exe in one case and Git Bash in the other case), so the most likely explanation is that $JAVA_HOME is set to different JDKs in the respective environments.
You can check the content of $JAVA_HOME with echo $JAVA_HOME.
I need to store locally emails downloaded via POP3 and so I'm tring to use JavaMail Mbox Store, which is part of the JavaMail source code but not compiled.
https://java.net/projects/javamail/pages/MboxStore
I've followed the instructions at the end of this page, but with no luck. Here comes what the instructions says:
export MACH=`uname -p`
export JAVA_HOME=/usr/java
cd mbox
mvn
cd native
mvn
I've changed the JAVA_HOME variable according to my environment. I get no error until the last command. The docs says that by default these are the options used by maven:
mvn -Dcompiler.name=c89 \
-Dcompiler.start.options='-Xa -xO2 -v -D_REENTRANT -I${env.JAVA_HOME}/include -I${env.JAVA_HOME}/include/solaris' \
-Dlinker.name=c89 \
-Dlinker.start.options='-G' \
-Dlinker.end.options='-L${env.JAVA_HOME}/jre/lib/${env.MACH} -lmail -ljava -lc'
I've changed the compiler name to gcc and removed some options unrecognized by gcc (-Xa and -x02). Unfortunately, it complains about a missing maillock.h.
Do you know where I can find a complete list of dependencies? Am I doing something wrong with options? I've tried to look for any pre-compiled version, but I had no luck.
I'm trying to compile on Slackware 14.1.
On Ubuntu/Debian/Mint you need the liblockfile-dev package.
To build on Debian Whezzy I had to manually set the archecture and then add the -shared option to stop the undefined reference to main (asumming the linux equivalent to -G in Solaris). Also add the additional library path for linjvm which is under the server directory
export MACH=amd64
mvn -Dcompiler.name=c89 \
-Dcompiler.start.options='-v -D_REENTRANT -I${env.JAVA_HOME}/include -I${env.JAVA_HOME}/include/linux' \
-Dlinker.name=c89 \
-Dlinker.start.options='-shared' \
-Dlinker.end.options='-L${env.JAVA_HOME}/jre/lib/${env.MACH} -L${env.JAVA_HOME}/jre/lib/${env.MACH}/server -llockfile -ljava -jverify -ljvm -lc'
I am trying to install a local version of the Validator.nu server and it keeps failing on trying to build the HTML Parser.
It says it can't find the JAVA_HOME variable which I have set in my .bashrc file and shows correctly when I type "echo $JAVA_HOME" at the prompt
Ideas appreciated thanks
Error output
"hg" pull --update -R build https://bitbucket.org/validator/build/
Not trusting file build/.hg/hgrc from untrusted user dave, group dave
Not trusting file /home/dave/src/checker/build/.hg/hgrc from untrusted user dave, group dave
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
pulling from https://bitbucket.org/validator/build/
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
searching for changes
no changes found
Error: The JAVA_HOME environment variable is not set.
Set the JAVA_HOME environment variable to the pathname of the directory where your JDK is installed.
Instead of:
$ sudo python build/build.py all
try:
$ sudo -E python build/build.py all
The sudo command for security reasons resets the environment (so your JAVA_HOME for the python process is wiped out even when it's exported). The "sudo -E" will preserve the environment.
I assume (from tag) you use ubuntu.
list versions of installed javas in your system:
dave#ubuntu:~$ update-java-alternatives --list
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
Note, that if you set JAVA_HOME in ~/.bashrc it will be set only in your terminal sessions.
Unless you export it, it will be set only for your current shell process (not subprocesses like mercurial).
add line to your .bashrc:
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk"
open a new terminal and test it:
$JAVA_HOME/bin/java -version && echo java seen by bash
bash -c '$JAVA_HOME/bin/java -version && echo java seen by bash subprocesses'
If you want to set environment for all processes (not only started by hand from terminal), you can:
dave#ubuntu:~$ sudo $EDITOR /etc/environment
After tackling this for the last 4 days I have managed to get the validator.nu server running on my local Ubuntu VM and so I thought I would update this thread in case anyone else runs in to the same issues.
I am still not 100% sure where the original issue with the JAVA_HOME variable was coming from but I suspect (although I am not an expert at this) that it had something to do with the way I was using sudo to run the python build.
I was initially following the instructions on http://about.validator.nu/#src but using
$ sudo python build/build.py all
This was because part of the build needed the correct permissions to work.
This is my step-by-step process which starts from a clean install of Ubuntu 11.
installed ubuntu 11
opened the terminal
sudo /bin/bash <----------- I THINK THIS IS THE CRUCIAL LINE
apt-get install mercurial
apt-get install subversion
apt-get install openjdk-6-jre
apt-get install openjdk-6-jdk
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
follow rest of http://about.validator.nu/#src instructions
I'm going to need to do it again when I set this up for the internal network for our build scripts so i'll edit this if I've missed out on anything.
Hope this saves another person's headache and lost days!