You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by kunduruswaroop <sw...@hotmail.com> on 2008/11/09 16:48:57 UTC

How to add a jar in project package.

Hello Every one,

I am learning Maven2. I have an application and it uses log4j. When I
package and port the application to a fresh box with out log4j it is
failing.

What I like to see is when packaging my application, my app should include
log4j.jar file. I request you to let me know what change I should make on
pom.xml to include log4j.jar in the application jar.

Thanks in advance.
Regards,
Swaroop Kunduru.
-- 
View this message in context: http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20407563.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by Wayne Fay <wa...@gmail.com>.
> What I like to see is when packaging my application, my app should include
> log4j.jar file. I request you to let me know what change I should make on
> pom.xml to include log4j.jar in the application jar.

Most people use the assembly plugin to create a zip file containing
their project jar(s) as well as the jars of their dependencies. This
is well documented in the plugin docs on the Maven site, as well as in
the Better Builds with Maven free ebook.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by Wayne Fay <wa...@gmail.com>.
> I am using Sun JVM from JDK1.5. I wanted a structure in the project jar file
> it should include log4j jar file so that I can port this entire jar to
> different machine where there is no Maven and and run the class.

You have two options:
1. Create an "uberjar" using the minijar plugin which contains all of
your class files as well as the class files of all of your
dependencies. Thus, the log4j class files etc will be mixed in with
your project files in a single jar. [1]
2. Create a zip file using the assembly plugin which contains your jar
file plus the dependency jar files, perhaps in a lib/ folder. You
might also include a shell script which sets up the java -cp ...
command line for your users so they can simply type run.sh (or
run.bat) and everything will run. [2]

Maven can help in either situation.

[1] http://mojo.codehaus.org/minijar-maven-plugin/usage.html
[2] http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by kunduruswaroop <sw...@hotmail.com>.
Thanks Tomek This is what I am expecting. But I have a trouble in this. I
open another thread for it as I got this problem solved.

Regards,

Swaroop Kunduru,



Tomasz Pik wrote:
> 
> On Mon, Nov 10, 2008 at 9:51 PM, kunduruswaroop <sw...@hotmail.com>
> wrote:
>>
>>
>> Wayne
>>
>>
>> I am using Sun JVM from JDK1.5. I wanted a structure in the project jar
>> file
>> it should include log4j jar file so that I can port this entire jar to
>> different machine where there is no Maven and and run the class.
> 
> You may use jar-with-dependencies:
> http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies
> Then, after 'package' you'll have two jars:
> my-jar-1.0-SNAPSHOT.jar contains your classes
> and my-jar-jar-with-dependecies-1.0-SNAPSHOT.jar
> contains your classes and classes from your dependencies.
> This will not be 'jar within a jar' but just a regular jar.
> I think that's what you're looking for.
> 
> HTH,
> Tomek
>>
>>
>> Regards,
>>
>> Swaroop Kunduru.
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20427615.html
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20431536.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by Tomasz Pik <to...@gmail.com>.
On Mon, Nov 10, 2008 at 9:51 PM, kunduruswaroop <sw...@hotmail.com> wrote:
>
>
> Wayne
>
>
> I am using Sun JVM from JDK1.5. I wanted a structure in the project jar file
> it should include log4j jar file so that I can port this entire jar to
> different machine where there is no Maven and and run the class.

You may use jar-with-dependencies:
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies
Then, after 'package' you'll have two jars:
my-jar-1.0-SNAPSHOT.jar contains your classes
and my-jar-jar-with-dependecies-1.0-SNAPSHOT.jar
contains your classes and classes from your dependencies.
This will not be 'jar within a jar' but just a regular jar.
I think that's what you're looking for.

HTH,
Tomek
>
>
> Regards,
>
> Swaroop Kunduru.
> --
> View this message in context: http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20427615.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by kunduruswaroop <sw...@hotmail.com>.

Wayne


I am using Sun JVM from JDK1.5. I wanted a structure in the project jar file
it should include log4j jar file so that I can port this entire jar to
different machine where there is no Maven and and run the class.


Regards,

Swaroop Kunduru.
-- 
View this message in context: http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20427615.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by Wayne Fay <wa...@gmail.com>.
> I wanted log4j as a library of original project and I am expecting it to be
> inside original project jar file.

What classloader/JVM are you using which supports a Jar inside a Jar?
Or did you want the jar unzipped, and the files therein bundled up
with your project's jar?

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by kunduruswaroop <sw...@hotmail.com>.
Wayne,

http://www.nabble.com/file/p20427304/my-app.zip my-app.zip 

I am including all my files in zip format. I did exactly what you said.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
    <build>
    <resources>
      <resource>
	<directory>src/main/resources</directory>

        <!-- 
	<properties>
		<property>
			<name>log4j.configuration</name>
			<value>log4j.properties</value>
		</property>
	</properties>
	-->
      </resource>
    </resources>
     
      <plugins>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
         
          <descriptors>
            <descriptor>src/assemble/distribution.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>

     </plugins>
  </build>
 
 
</project>




<!-- ASSEMBLY FILE -->
<assembly>
  <id>repository</id>
  <formats>
    <format>jar</format>
  </formats>
  <repositories>
    <repository>
	<!--
      <includeMetadata>true</includeMetadata>
      <outputDirectory>maven2</outputDirectory>
     -->
       <includeMetadata>false</includeMetadata>
      <outputDirectory></outputDirectory>
     
    </repository>
  </repositories>
</assembly>


What this is doing is it creating another jar file there is a folder inside
with the name of original project and all the dependent log4j package is
inside that.


I wanted log4j as a library of original project and I am expecting it to be
inside original project jar file.

Regards,

Swaroop Kunduru.
-- 
View this message in context: http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20427304.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by Wayne Fay <wa...@gmail.com>.
> Thanks for your reply. I read all sorts of documentation in the net and all
> the books. None of them explain how to use assembly tag to include 3rd party
> jars.

I assure you, all of the examples for the assembly plugin do *exactly*
what you are requesting. If you are unable to make it work, that is
another issue. In this case, you need to provide more details.

Based on what you've mentioned, you probably want to use the
descriptor "jar-with-dependencies":
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by kunduruswaroop <sw...@hotmail.com>.
Wayne,

Thanks for your reply. I read all sorts of documentation in the net and all
the books. None of them explain how to use assembly tag to include 3rd party
jars. 

I request you to please post any example if you have. I also request you to
take log4j as example.

Regards,

Swaroop Kunduru.
-- 
View this message in context: http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20413030.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to add a jar in project package.

Posted by Baptiste MATHUS <ml...@batmat.net>.
... Your question is missing a lot of information to let people help you.
What is the packaging you're using? What's the "application" you're
packaging? Could you give us an excerpt of your pom.xml?

If you're packaging a war, then just check that log4j dependency was
specified and NOT with provided scope.

Cheers.

2008/11/9 kunduruswaroop <sw...@hotmail.com>

>
> Hello Every one,
>
> I am learning Maven2. I have an application and it uses log4j. When I
> package and port the application to a fresh box with out log4j it is
> failing.
>
> What I like to see is when packaging my application, my app should include
> log4j.jar file. I request you to let me know what change I should make on
> pom.xml to include log4j.jar in the application jar.
>
> Thanks in advance.
> Regards,
> Swaroop Kunduru.
> --
> View this message in context:
> http://www.nabble.com/How-to-add-a-jar-in-project-package.-tp20407563p20407563.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !