Developing on the Mac with IntelliJ 9.0.2 Community Edition.
I have a program which depends on two library jars. I have figured out how to get IntelliJ to make me a jar of my source (with the Artifact tab), and even to include the two jars in it.
However, if I get a listing of the jar file it produces, it looks like this:
com/acme/MyClass1.class
com/acme/MyClass2.class
...
mylib1.jar
myLib2.jar
And, no surprises, if I double-click the jar file, it gets a NoClassDefFoundError the first time it tries to access a class in one or other library jar.
It seems I need to tell IntelliJ to "inline" the library jars -- but this menu option is always greyed out!
Does anyone have any idea how to get jars inlined in a jar artifact?
IDEA doesn't support it yet, you can use Ant integration to package your jar (either by unpacking all the jars into the temp folder and then packaging the project output plus this temp folder into the single jar or by using some Ant task like jarjar).
If you want this feature to appear in the future IDEA versions, please vote for the request.
Having the dependency JARs included in your JAR should allow yoru code to run successfully. You probably don't have the JARs on your classpath.
I will use Maven Assembly plugin. Its simple and will give you a neat little jar file..
Related
I am trying to install some dependencies using maven in a spring boot project.
I am looking for a jar
org.apache.maven.plugins:maven-resources-plugin:jar:3.1.0
But I wanna know if the jar file should have this name maven-resources-plugin, or if the file name is not important for maven. I mean if maven will automatically know which jar file should use.
I will appreciate any help or feedback.
That is a plugin, not a dependency as such (meaning that Maven needs it for building your project, your code doesn't need it to compile or run).
You should only have to specify the plugins groupId, artifactId and version plus any configuration in your pom.xml, and Maven knows exactly what jar to get and how to use it.
See https://maven.apache.org/plugins/maven-resources-plugin/plugin-info.html for further information.
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 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.
I am trying to move my MyEclipes projects to maven. But of course there are problems. After creating a web priject I get missing jar files - about 5
org.springframework.security jar files e.g. org.springframework.security.ldap-3.0.5.RELEASE
show as missing in the jar build path. They are not in the corresponding .m2 directory. I un-installed ME4S, and deleted .m2, which force .me to be rebuilt on re-install, but it has the same problem.
How do I fix this?
It would be very helpful to understand how the .m2 process works - where is this coming from and how is it controlled?
I am not sure about the MyEclipse part, but this seems to be a pure maven question.
Maven (2/3) uses the pom.xml. This file describe your project. In that file you should define a list of dependencies (which can have their own dependencies and so on).
Maven read the pom.xml and build the classpath accordingly using direct and transitive dependencies.
You can use the mvn dependency:tree command to see how your classpath is built.
More on the plugin page
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)