spring boot project, build as a executable jar, but I found cannot extract the executable jar, e.g.
jar xvf spring-boot-foo-0.0.1-SNAPSHOT.jar
nothing output.
But when extract a normal jar, it is successful
jar xvf mysql-connector-java-5.1.38.jar
created: META-INF/
inflated: META-INF/MANIFEST.MF
created: META-INF/services/
...
why is this?
You can less your jar file and will find the following:
#!/bin/bash
#
# . ____ _ __ _ _
# /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
# ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
# \\/ ___)| |_)| | | | | || (_| | ) ) ) )
# ' |____| .__|_| |_|_| |_\__, | / / / /
# =========|_|==============|___/=/_/_/_/
# :: Spring Boot Startup Script ::
#
That is, it's a bash file follow a jar, not a normal jar.
you can extract this file use : unzip spring-boot-foo-0.0.1-SNAPSHOT.jar
or set the executable flag of spring-boot-maven-plugin to false to make a normal jar file.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>false</executable>
</configuration>
</plugin>
I normally use 7zip to extract files on windows and it didn't work as well. Thanks to #peace0phmind I tried to open it with my Text editor (notepad++) and I saw that the content is a shell script followed by binary code.
I just removed all bash script lines, saved the file and now I can open it with 7zip.
When using 7zip to open a Springboot executable jar you need to right-click on the .jar file and select the second 7zip option "Open Archive..." and select zip as format from the additional formats.
Selecting "Open as archive" won't work.
Upgrade to Spring boot 2.6.7 and create a executable jar using gradle bootJar task.
Now you can extract the jar eventhough it is executable.
Not sure if this is a bug in Spring boot 2.6.x
I tried with Spring boot version 2.6.7, Spring cloud version 2021.0.0, gradle 6.9.0
I am unable to restrict the jar from extracting it using any standard zip archive tools.
Related
I'm just on:
https://openjfx.io/openjfx-docs/#modular
trying to create a jar I can run on other systems (that do not have the javafx libraries as would happen with a non-developer layman user) and they've told me to use this:
dir /s /b src\*.java > sources.txt & javac --module-path %PATH_TO_FX% -d mods/hellofx #sources.txt & del sources.txt
What is mods/
Where is that supposed to be? Are they talking about out/ ?
The doc you have linked refers to this sample.
If you clone the sample, and follow instructions on how to compile and run the project, the first command can be divided in three parts:
dir /s /b src\*.java > sources.txt & \
javac --module-path %PATH_TO_FX% -d mods/hellofx #sources.txt & \
del sources.txt
The first part just gets all the Java files in the src path and adds that to sources.txt file:
C:\path\to\hellofx\src\module-info.java
C:\path\to\hellofx\src\hellofx\HelloFX.java
The second part calls the javac command (see reference) to compile the content of sources.txt, adding the required --module-path option to include the JavaFX modules, and also adding the output or destination -d option:
-d directory
Sets the destination directory for class files. If a class is part of a package, then javac puts the class file in a subdirectory that reflects the package name and creates directories as needed.
This means that we are going to compile hellofx.HelloFX.java into the directory mods/hellofx, resulting in:
C:\path\to\hellofx\mods\hellofx\module-info.class
C:\path\to\hellofx\mods\hellofx\hellofx\HelloFX.class
The third step will just remove the sources.txt file.
And now you can run your module:
java --module-path "%PATH_TO_FX%;mods" -m hellofx/hellofx.HelloFX
You can specify any directory for the output, of course, so you can change it to out or build for instance, but then make sure you modify it accordingly in the rest of the instructions.
Can I somehow build multiple projects with one root project.json file (or otherwise)? For example, one library, one test project, and one command line? If so, how?
I may be one year late in answering, but may be it is still useful for somebody who lands here after this.
dotnet build no longer uses project.json, instead uses *.csproj. And dotnet build can now take a directory name as an argument, and uses the *.csproj within that directory for the build. This being the case, the easiest way to build from a top-level-directory goes like this:
Assuming the structure of your projects is:
src
|
+ -- proj1
|
+ -- proj2
|
+ -- proj3
|
.
.
Just go to the top-level directory (src in this case), and type this:
Get-ChildItem -exclude ".vscode" | %{Write-Host -ForegroundColor DarkMagenta "Building $_..."; dotnet build $_;}
I normally use PowerShell within VSCode, and hence you see the -exclude ".vscode" and PowerShell commands Get-ChildItem (aliased also as simply 'dir') and Write-Host.
Hope this helps.
If all of your projects are stored in a structure like this :
<root>/src/Project1
<root>/src/Project2
then you can use a single command with a globbing pattern to build all of the projects at once:
dotnet build src/**/project.json
From what I am aware of, you'll still need individual project.json files for each project though.
Go to the root of your solutions and run the following PowerShell (only for .NET Core projects)
$baseDir = (Get-Item -Path ".\" -Verbose).FullName
Write-Host ("Scanning *.sln files in " + $baseDir)
$solutionPaths = Get-ChildItem -Path $baseDir -Include *.sln -Recurse
Write-Host ("Total found: " + $solutionPaths.Count)
foreach ($solutionPath in $solutionPaths) {
Write-Host ("Building => " + $solutionPath)
dotnet build $solutionPath
}
I am using the build 9-ea+129-jigsaw-nightly-h5332-20160730
I have a very simple module with a Main class and a module-info.java
I compile the module using javac --module-source-path and everything is ok. The class files are being generated for both module-info.class and Main.class
javac -d modules --module-source-path src $(find . -name "*.java")
When I try to create the modular JAR file with the jar tool, I get the following error message:
module-info.class found in a versioned directory without module-info.class in the root
My module-info.class is there in the root directory.
I run:
$ jar --create --file mlib/ModuleFirst#1.0.jar --module-version 1.0 --main-class com.firstmodule.Main -c modules/com.firstmodule
Can you tell me why do I get this error and what I did wrong?
Thank you
Regards
I have the same problem
You should change a lot your command
$ jar --create --file mlib/ModuleFirst#1.0.jar --module-version 1.0 --main-class com.firstmodule.Main -C modules/com.firstmodule .
You must use the capital C and put the dot at the end of line
My Qt project structure is similar to this:
Directory Structure:
|
|--- dir
| |
| | - a.c
| | - a.h
| | - test.pro
|--- dir1
| | - b.c
| | - b.h
test.pro
SOURCES += a.c \
../dir1/*.c
HEADERS += a.h \
../dir1/*.h
When I try to build the project I get the error:
:-1: error: No rule to make target `../dir1/*.c'
Is there anyway to include source files which are outside the .pro file?
And also have them show in the Projects pane on the left in Qt Creator?
Wildcards in qmake (.pro file) work only for files in current project directory. For subfolders it does not work. So the proper solution is to add each file separately.
The issue was raised on the Qt bug tracker QTCREATORBUG-8925. The ticked is closed as a new feature request or due to multiple problems:
Using wildcards in .pro files creates multiple problems, e.g. adding a
additional file won't automatically compile it. Nor would deleting a
file automatically remove it from the Makefile
However, there is undocumented function listed on the wiki Undocumented_QMake
files(glob) — Returns a list of files which match the specified glob
pattern.
So, if the above problems of using globbing patterns are acceptable it can be used as
SOURCES += $$files(../dir1/*.c)
I have a home directory in my unix box. I would like to setup a number or shortcuts in it to point to the latest file in another directory and the link will update if a newer file is created.
Is this possible?
So far I able to get the latest file:
ls -lrt | tail -n1
Thanks
[EDIT]
Perhaps I could even create a shell instead of a softlink which finds the latest file and returns it so I can open/grep/delete etc?
In bash, this will make a link to the latest file or directory in "target-directory" called "latest":
ln -s target-directory/`ls -rt target-directory | tail -n1` latest
And this will wait for a change in "target-directory" before returning:
inotifywait -e attrib target-directory