Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Maven Project appears in another project as directory not a jar

So, I created a Spring Maven Project, a Dao Project, which works great. All the code is in the correct place, all the unit tests run, and I can do a mvn clean install. I can see in the target directory that there is a build jar, and everything in it looks fine. I can also confirm that when I check my local .m2/repository, the latest jar I just built is in there.

Here is a small segment of that pom.xml:

<modelVersion>4.0.0</modelVersion>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Project DAO</name>

Now, I am creating a new Spring Maven Web-Project for my UI, and this pom.xml starts out like:

<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-ws</artifactId>
<name>My Web Project</name>
<packaging>war</packaging>

Also in this pom.xml file, one of the first dependencies I have is:

    <!-- My DAO ProjectDependencies -->
    <dependency>
        <groupId>com.tom.myproject</groupId>
        <artifactId>myproject-dao</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

I can see in eclipse that when I try to access the classes from this dao jar, that seems to work fine. When I compile the code here, that all works fine. And when I do a "mvn clean install" to build this war, I can see the target directory, and all the needed classes and jars come in, obviously there are hibernate, logging, and spring classes that are there in the WEB-INF/lib directory.

Now this is he part where the question comes in ... Why does the myproject-dao show up under WEB-INF/lib as WEB-INF/lib/myproject-dao-0.0.1-SNAPSHOT.jar but appears as a directory, and not a jar?

Certainly when I pull in other jars, they are just .jar files and not directories.

I should add, when you look in the Eclipse project under maven dependencies, the icon for all the other jars show them as files. The icon for my myproject-dao.jar uses the icon for a folder/directory, so clearly a directory named "myproject-dao.jar" is being created and not a file with zipped up contents into a jar file.

When I build the war file, and deploy the war, the app says it cannot find any of the classes in the myproject-dao.jar directory. I have to delete the FOLDER "myproject-dao.jar" from the WEB-INF/lib directory and manually copy over the FILE "myproject-dao.jar". I can then clearly see the icon that means this really is a file.

This is probably a simple fix, so if you can help me out, that would be great.

ANSWER:

I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.

Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.

So, all I have to do build my dao.jar file with maven, and when it is successful, it is done. Then I have to CLOSE the project within Eclipse. In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.

I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.

In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.

like image 546
tjholmes66 Avatar asked Aug 15 '13 16:08

tjholmes66


People also ask

How do I package a Maven project into a jar?

In order to compile the project into an executable jar, please run Maven with mvn clean package command.


1 Answers

I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.

Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.

So, all I have to do build my dao.jar file with maven, and when it is successful, it is done. Then I have to CLOSE the project within Eclipse. In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.

I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.

In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.

Thanks for the help!

like image 51
tjholmes66 Avatar answered Oct 23 '22 09:10

tjholmes66