has any way to read a file inside on dependency?
For example, I have my pom.xml and I using the maven-antrun-plugin to copy the .war generated to my remote server, but i need to pass two attributes: keyfile and knowhosts, today, I have these files inside my project, in java/resources path, but i would like to know if has any way to wrapper these files in a .jar, and use this as dependency in my project, and read theses files from this dependency.
Thank very much!
I'm not sure if I understand your question correct so let's summarize your question how I understand it:
You have a project based on Maven and build a WAR file for deployment on an application server.
In your current situation you have two files in your projects resource folder that you read from/with your project code.
You want a situation that the two files are packed in a custom jar file and put that file as dependency on the classpath/in the pom file. The question is if you can still read them from your project code.
Yes, that's possible. If you add the dependency to the dependency list in the pom file the file will be also included in the war file and then available on the classpath of your application.
Only if your project jar is marked as sealed it won't work (Sealed jar files only can read classed from it's jar file and I think that is also not possible for resource files).
If this is also a good solution is more complex to answer and I can't answer that with the current limited info I have about your project.
Related
Is there a way we can load all the jar files inside a folder, as dependencies in a maven project.
So that, I do not have to mention each and every jar files in pom.xml, just mention or tell maven to pick all the jar files from folder 'x' and build the system.
Is this supported by maven?
I think this is supported by ant. Not sure whether gradle supports either.
In
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
you see that you can reference single files, but there is no mechanism for directories. As I mentioned in the comment, using the disk is discouraged in general.
If you need the same set of dependencies in many projects, you can write a pom for that and use it (as parent or by setting a dependency to it).
I want to include source files also in Maven - War file . Some plugins in maven will do that but they are including source files in classes folder. But my requirement is that when I import the same war file again into eclipse I should be able to work on that war like any other normal war.
Basically I should be able to work on the same war after importing it to eclipse when I build maven project. (I'm using maven3. )
I remember that's not trivial because the war-plugin doesn't support the handy includes-configuration-element you know from the jar-plugin by default.
Therefore I suggest you to use the maven-assembly-plugin to configure the inclusion of your sourcefiles. You only need to define an assembly descriptor, where you list includes and excludes of your war-package. Maybe you can reuse one of the predefinied assembly descriptors to save some time.
As part of my build process, I am generating a separate artifact (compressed file with static web files inside) in the which I would like to contain the same information that is in the manifest file generated by the war plugin. The manifest file is generated correctly into the war file, but I'd like access to it so I can copy it and put it in my compressed file as well.
In the documentation for the maven-war-plugin:manifest goal, it reads:
The manifest file is created in the warSourceDirectory.
Which defaults to the location: ${basedir}/src/main/webapp
However, the only manifest that is generated is within the war. It doesn't make sense to me either that the generated manifest file would be put into my source. I would think that it would be put in the target where the war is packaged from.
Am I missing something?
If you look at the built-in lifecycle reference you will see that at no point in the <packaging>war</packaging> lifecycle is the war:manifest goal bound to any phase.
Thus by default this goal will not execute (unless you add an execution).
If there is a MANIFEST.MF file at ${basedir}/src/main/webapp/META-INF/MANIFEST.MF then when the war:war goal is executing it will use that file rather than generating the MANIFEST.MF on the fly and embedding it straight into the .war file without creating an intermediary file.
From what I can tell, the war:manifest goal is designed to be used to generate a template MANIFEST.MF which you can then customise and use going forward.
The war plugin has a number of goals which I would tend to advise keeping clear of:
war:inplace
war:manifest
The reason is because both of these goals modify the files in your src tree which goes against the standard Maven practice of only touching files in target (which makes for a very nice mvn clean as you need only remove the target)
With regards to your question, the key thing is that you are generating a separate artifact. Maven works best when you stick to one artifact per Maven module. Thus the separate artifact will have a separate module. You just add the .war as a dependency (remember <type>war</type>) and then use dependency:unpack-dependencies to unpack the .war file... you can have it only unpack the META-INF/MANIFEST.MF and if that ends up as target/${project.build.finalName/META-INF/MANIFEST.MF then when you are packing up this second artifact you will ensure it has the same manifest as your .war file.
I have created an OSGi bundle and I want to add two external jar files to it called mediasenseplatform.jar and tinyos.jar So I added this line into my manifest file:
Bundle-ClassPAth:.,mediasenseplatform.jar,tinyos.jar
but it doesn't work and I don't see these files in my bundle jar file. How can I solve this problem?
OSGi doesn't make jar files, it is a platform for deploying and running them. If you want to include these jars in your bunde (which is just another jar) then you have to put them in there yourself.
There are build tools like maven which can do this for you.
You may also want to take a look at this related question.
How I can configure the Jar task in Gradle to create the jar file with the directory entries?
Like the "filesonly=false" option of Ant's jar task, or the Eclipse option "Add directory entries" in the Export Jar dialog.
To be honest, I cannot see where is the difference between a Jar with directory entries and one without them, but I have a Spring project which uses some #Component configured bean from an external Jar: if that Jar has the directory entries, Spring is able to find the beans, otherwise not (as stated in the Spring documentation itself).
UPDATE: I figured out that in the last releases (I'm currently using 1.0-m6) Gradle already was creating the Jar the right way, that is: with all the proper directory entries. My problem was due to a bug in a task of my own that was building the classes dir with incomplete content.
I still haven't found a way to have Gradle add the directory entries, but as I already stated in the question, the last releases of Gradle do it properly. So if anyone has same problem like me, a solution is to upgrade Gradle ;o)