aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven Testa as standalone (jar) application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Maven Testa as standalone (jar) application" Watch "Maven Testa as standalone (jar) application" New topic
Author

Maven Testa as standalone (jar) application

Swaroop Kunduru
Ranch Hand

Joined: May 22, 2006
Posts: 33
I have an application and it also have tests which can run with mvn test command. I wanted the tests to develop as standalone jar file. How can I (Develop) export as jar file all the tests in maven.

Regards,

Swaroop Kunduru.


Regards,
Swaroop Kunduru
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16058
    
  21

There's a separate forum for Maven questions. You'd get more/better answers if you'd asked over there.

Maven is designed with the idea that it will build the deployable product and that the deployable product should not contain anything but production elements in it. In other words, no test classes, test data or stuff like that. The standard way of doing testing with Maven involves a completely separate source tree from the production elements. Instead of src/main, there's src/test, and nothing that's in - or produced from - that source tree will be placed in the final product. The tests are all compiled to a temporary directory.

An individual Maven project can only produce one artifact (jar). So the only way that you could run standalone tests from a jar would be to move the tests from src/test/java to src/main/java. And if you did that, the test code would then end up in production, which not only bulks up the production deployable, it introduces possible security exploits.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30516
    
150

Tim Holloway wrote:There's a separate forum for Maven questions. You'd get more/better answers if you'd asked over there.

That was my doing. This thread started out in test and I moved it to IDEs instead of Build tools. Fixing so it is in the best forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2374
    
  28

Maven Jar plugin allows you to packages test files into a jar. You don't need to move source from src/test to src/main. Look at the Usage page and scroll down to "How to create a jar containing test classes"
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16058
    
  21

Jayesh A Lalwani wrote:Maven Jar plugin allows you to packages test files into a jar. You don't need to move source from src/test to src/main. Look at the Usage page and scroll down to "How to create a jar containing test classes"


I stand (semi) corrected! The procedures listed will allow you to create a test jar. However, that jat will contain only the test classes and resources and will be separate from the jar containing the actual product. At least as I read it. The "easy" way allows you to keep the test in the src/test tree. The "recommended" way is basically what I'd proposed earlier.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2374
    
  28

I don't really like the "recommended" way simply because once you move your tests outside of the module you are testing, somebody is sure to forget to execute the test, or, heaven forbid, might even cause the tests to stop compiling. I like to tell my developers "Run mvn clean install before you check in.. No exceptions"
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16058
    
  21

Jayesh A Lalwani wrote:I don't really like the "recommended" way simply because once you move your tests outside of the module you are testing, somebody is sure to forget to execute the test, or, heaven forbid, might even cause the tests to stop compiling. I like to tell my developers "Run mvn clean install before you check in.. No exceptions"


I think you can reduce that by making the test jar a test dependency in the project. But definitely, out of sight, out of mind. And maintaining 2 projects instead of 1 is more annoying.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

You could attach the test JAR to your build. Then both the test JAR and app JAR would be in the repository.

I can think of two ways to do this:

1) Set a finalName for the test JAR within the jar:test-jar plugin properties using something like "${project.build.finalName}_tests" and then use the Build Helper plugin (http://mojo.codehaus.org/build-helper-maven-plugin/) to attach the test JAR to the build.

2) Modify the Jar plugin to add an attach option and a classifier option. Actually, I'm rather surprised that these options don't already exist. I can think of some cases where tests for one project would like to depend on tests for another project, especially of those projects are related. I would then submit this patch back to the community.

If I had to do this, I would opt for option 2.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven Testa as standalone (jar) application