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.
Related
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.
Intellij fat one jar artifact does not generate a working output. Below you can see my settings and project structure(left). When i click build artifact and then the generated output, nothing happens.
mssql-jdbc-6.2.0.jre8.jar has the digital signature (MSFTSIG.RSA and MSFTSIG.SF files). When the jar is repackaged, the signature becomes broken. If you remove these files from the jar (either original one or the artifact), it should start fine.
Vote for this issue to get it addressed in the future updates.
I just opened generated jar file with winrar. And deleted SIGNINGC.SF file in META-INF folder
I'm using IntelliJ Idea v11.4 and when I compile my project in the target/classes directory not only class files are listed but java files too. For every class file I find the corresponding java file...is this the right behaviour?
In my project I use maven to create the projects jar file and this jar file contains these java files too.
How can I prevent the java files from being copied in the jar file? I want to obfuscate the jar file to publish it in the net so if the java files are part of it too the obfuscation becomes useless.
Thanks for your help in advance!
Follow this guide:
You should build the Jar file using Build | Build Artifact menu item.
Note that by default all libraries are extracted to the target Jar. It became possible with addition of the new Extracted Directory element. Using such element you can extract a directory from a Jar file and place it into the output of your artifact:
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
I currently started working on a maven web-app project that needs to be launched with the jetty:run-exploded goal for development/debugging in eclipse.
Now, I have an XML file which contents I need to access at runtime. My problem is: where to put the file so that the code that does the reading works both in "exploded" and packaged (i.e. in the WAR) mode?
Putting the file in src/main/java (so as to be in the classpath) won't cut it since maven filters out all non-java files on packaging.
When the file is in src/main/resources, one mean would be to figure out the root path of the project (during eclipse development) and look into that directory - but this won't be the case anymore when the project will be packaged.
Of course I could go into writing code that tries to read the file from both locations, but this seems rather cumbersome. Any suggestions?
Files in src/main/resources are copied to the target/classes directory and are available on the class path. Just read them from the class path. As explained in How do I add resources to my JAR? from the maven documentation (with a test resource here):
In a unit test you could use a simple
snippet of code like the following to
access the resource required for
testing:
...
// Retrieve resource
InputStream is = getClass().getResourceAsStream("/test.properties" );
// Do something with the resource
...
In such case I put the file under src/main/resources directory and use Spring's ClassPathResource. This way the file is accessible in IDE, during Maven build process and in runtime.