When I create an executable .jar file using IntelliJ, the .jar file always ignores it's own class-path in the manifest.mf file.
Thanks to this question: Executable JAR ignores its own Class-Path attribute I have been able to find that the cause of the problem is that during the creation of the .jar file, a META-INF/LIST.MF file is created. If I delete that file, everything works fine. However, unlike the question linked, my pom.xml file does not contain the command to create this file.
How do I turn this off in IntelliJ?
Try, when creating an artifact in IntelliJ,project structure -> Artifacts -> new from maven with dependencies, in the path for Directory for the META-INF/MANIFEST.MF, always change the path to the sibling resources directory, it should not be set tojava` directory.
Related
So what im trying to do is to build a JAR artifact which should include the necessary libraries as well as directories which are outside of the JAR file and can be looked at in the explorer.
I have already tried to add directories to the artifacts but these get put into the JAR file in a folder which i cant access later when converting it to a exe using launch4j.
Is there an option in Intellij to exclude directories from building into a JAR?
Edit: I want the output directory like this
Directory Structure
I have a multi-module project that goes as follow server-core -> server-game
The server-core module bundle an app.properties file which I would like to override certain values when I build the server-game's executable jar.
To do so, I added an eachFile closure on the jar task to update the file content while building the jar but it turns out when editing the file using the ant.propertyfile task, it won't appear edited in the resulting jar:
I tried with another property file named app2.properties which is located inside the server-game resource folder and this one get updated in the final jar. More confusing when I check the app.properties file in the gradle tmp folder used to build the final jar it is properly edited.
Also if I filter the files content it will be reflected properly on the final jar for both files.
It seems that files extracted from another archive are simply ignored. If it is the case I wonder why do gradle bothers extracting them in the first place ?
Any idea of what could be wrong here ?
Edit: I created a small github project that reproduce the issue. It is available here.
Run the fatJar task and you will see in its output that only the app2.properties is updated in the resulting jar even though the app.properties has been updated in the tmp folder it has been extracted to during the build process.
I want to run a liquibase update by the liquibase-maven-plugin, but the changeset yml file is inside a .jar that I pull in by dependency.
When I open the .jar with TotalCommander, it has the following structure:
xy.jar/changelog/changeset.yml.
I tried including it as a resource directory, but it failed telling me the .jar is not a directory.
I also tried building to a WAR and just setting the liquibase changeLogFile property to the path leading to the .jar, like {projectDir}/target/..war/..lib/..jar/changelog/myFile.yml
But maven could not find it this way.
Is it possible to access this file somehow?
You can read the file using below code.
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("changelog/myFile.yml");
Thanks for the reply, but the solution was simpler, I'm just rusty in this area :) I simply had to add the required JAR from the WAR as a Maven Dependency. This adds the JAR's content to the classpath in the Maven build process, so I can reference to it's files as they were on the project root path.
TLDR: add JAR as dependency in the pom and use the path:
<changeLogFile>changelog/xy.jar</changeLogFile>
I'm a Java and Maven newbie and I have a question about the default manifest file.
As far as I understand, a manifest is created when a Java application is built using maven and it is added to the generated jar file.
I've also seen lots of references to a manifest.mf file, which can be found in a directory called meta-inf. But I can't find it anywhere.
I have successfully built my Java application using mvn package. I can see the jar file but I can't find the manifest file anywhere. Is it automatically deleted when the build completes?
The MANIFEST.MF file is inside the jar in the META-INF directory. You can see the content of your jar with jar tf your_jar_file.jar
You can also unzip the content of your jar with jar -xf your_jar_file.jar.
I have an xslt that I want to add to my jar file when I do the maven build. I read int he documentation you can add stuff in the resources folder, and it will get picked up, but what if I want it to show up in a different folder - how do I make it go there in the jar?
If it's a JAR just add it in src/main/resources replicating the folder structure you want to be present in the JAR (the classpath root for a JAR is the very first level on it so it's easy).
In case of a WAR or other package types the method is very different