I'm following this tutorial which tries to minimize the JVM memory footprint by building a minimal JVM.
When I'm running jdeps -s myjar.jar I'm getting:
myjar.jar -> java.base
myjar.jar -> java.logging
myjar.jar -> not found
In the tutorial he solves this by running another command.
jdeps -cp 'lib/*' -recursive -s myjar.jar
I tried this but I'm getting the same result.
How to run it correctly?
For a Maven project, you can do it like this:
Run mvn dependency:build-classpath
Copy the output of the maven-dependency-plugin (the line after "Dependencies classpath:")
Run jdeps -cp <paste output here> -s -recursive myjar.jar
It is due to Bug in Jdeps and has been the same since JDK 8 at least.
You can see the actual Path parser checks if the -cp/-classpath argument list contains "dir/.*" format and not "dir/*" format as advertised by the docs, examples and the API's javadoc.
JdepsConfiguration.java:599
Related
I have a simple non-modular jar file main.jar that depends on libA.jar and libB.jar. These three jar files all reside in the current directory. I want jdeps (version 15.0.1) to generate a module-info.java file for main.jar. Here's my shell command (using cmd.exe on Windows):
jdeps --module-path . --add-modules=ALL-MODULE-PATH --generate-module-info . main.jar
This command indeed produces the desired module-info.java file but also issues this warning:
Warning: split package: org.example.main file:///D:/Temp/./main.jar main.jar
writing to .\main\module-info.java
The package org.example.main does only exist in main.jar - so I reckon there should be no warning.
Any hints as to why jdeps does see a problem here ?
I'm trying to run the .net core sonarscanner tool on Jenkins (running on Linux) like:
dotnet sonarscanner begin ...
But it's giving the error
Could not find 'java' executable in JAVA_HOME or PATH.
I'm not sure why this is as I am explicitly setting the path at the top of my pipeline:
environment {
JAVA_HOME="${tool 'openjdk-11'}/jdk-11"
PATH="${tool 'openjdk-11'}/jdk-11/bin:$HOME/.dotnet/tools/:$PATH"
}
And from running the following commands I can see this looks correct:
sh "echo \"Java Home:\" $JAVA_HOME"
Produces:
Java Home: /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11
And listing the directory:
sh "ls /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11/bin"
produces:
+ ls /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11/bin
jaotc
jar
jarsigner
java
javac
javadoc
javap
jcmd
jconsole
jdb
jdeprscan
jdeps
jhsdb
jimage
jinfo
jjs
jlink
jmap
jmod
jps
jrunscript
jshell
jstack
jstat
jstatd
keytool
pack200
rmic
rmid
rmiregistry
serialver
unpack200
Yet still, sonar scanner fails with the error:
Could not find 'java' executable in JAVA_HOME or PATH.
UPDATE:
Regarding Dimitry's comment - I am using the tools:
With this at the top of the pipeline:
tools{
jdk 'openjdk-11'
}
With regards to Marcinek's answer - good spot. I've realised that setting the JAVA_HOME at the top of the pipeline is not actually doing anything. Whatever I set it to, it remains as:
/var/lib/jenkins/tools/hudson.model.JDK/openjdk-11
The variable $JAVA_HOME should point to the main directory of java, where the bin folder can be found by appending bin
Your $JAVA_HOME variable is pointing to
Java Home: /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11
To find the java executable you have to append jdk-11/bin
Thus the correct path to JAVA_HOME should be:
/var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11
And the PATH should point to:
/var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11/bin
You can use 'tools' section to use java in your pipeline.
pipeline {
agent any
tools {
jdk 'your-jdk-tool-name'
}
Not working in Windows 10:
> jar xf file.jar
'jar' is not recognized as an internal or external command, operable program or batch file.
In a PowerShell, you should first:
$Env:Path+="C:\Program Files (x86)\Java\jre1.8.0_181\bin"
Change jre1.8.0_181 according to your installed Java Runtime Environment. For sanity check, you can print the updated path:
$Env:Path
Then:
java -jar -h
I still haven't figured how to get the xf subcommand to work though.
Set the JAVA_HOME in Environment variable.
Then set path.
then open a new Command prompt and type
$ javac -version
It should print something like that
javac 1.8.0_152
Now try
I'm having troubles with converting my javac command as used under windows (my libraries are placed within the lib folder, the source code within the src folder, and the compiled code should be placed within the bin folder):
javac -cp lib/\* -d bin src/\*.java
into the correct linux javac command. I have tried many variations including
javac -cp lib/* -d bin src/*.java
but that doesn't seem to work :
"invalid flag: lib/org.eclipse.paho.client.mqttv3-1.0.2.jar".
I am looking for a solution to this already quite some time, so any advice on this would be highly appreciated!
This is one of those odd things that happens when you don't put quotes around an argument.
Solution worked out in comments section: "lib/" instead of lib/
javac -cp "lib/*" -d bin src/*.java
The other issue was that ; is needed instead of : in Linux for classpaths.
I'm using Tomcat7 , jdk 1.7.0_55 & eclipse, when I trying to compile the entire project(Java Code) using COMMAND PROMPT, its showing Error Like
javac: invalid flag: D:\COMPILE\lib\activation-1.1.jar.
The given below steps are followed to compile the code.
Step.1: dir *.java /s /b > FilesList.txt
Step.2: javac #FilesList.txt -d compiledCode -cp D:\COMPILE\lib\*.jar
After run the Step.2 command its showing Error.so I removed the error jar file from my lib folder & run the command but its showing same error with another jar.
Note: I Already have ANT build.xml but I want to compile the project through COMMAND PROMPT.
The lib*.jar gets expanded by the command shell. You need to avoid that by using quotes.
***** -cp "D:\COMPILE\lib\*" *****
The argument to -cp is a single path list (like $PATH, not multiple arguments with one path each). Multiple files can be separated by : (or ; on Windows)