Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

difference between clean from project tab and clean using maven in eclipse?

 
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Eclipse, I can see that one can do clean/build using two ways:

1. Go to project.Select Clean,Select the project.

2. Right click on the project and run as maven clean.

What is the differerence that it makes ?

Thanks
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, yes I should have asked this in the Eclipse forum.
 
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse actually uses the same mechanism to run Maven that it uses on its regular Project Run and Project Debug menus. When you use the Maven plugin's "clean" menu, it's internally doing a "mvn clean" just like on the command line.

On the other hand, it looks like you might possibly be breaking the rules for project cleaning in Maven. By default, "clean" will delete the target directory and its children. You should not interfere with this action. The expected action in Maven is that in most cases, if you do a "mvn clean", zip the cleaned project and email it to Ulan Bator, the recipient could easily do a Maven build where the entire project will reconstruct exactly as it did for you with no external setup or directory structure required other than an installed copy of (compatible) Maven and a JDK. If you have static resources that need to go into that product, you'd typically place them under src/main/resources (or src/main/webapp, if it's a WAR). Everything under target should be considered subject to unpredicable modification or deletion.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Eclipse actually uses the same mechanism to run Maven that it uses on its regular Project Run and Project Debug menus. When you use the Maven plugin's "clean" menu, it's internally doing a "mvn clean" just like on the command line.

On the other hand, it looks like you might possibly be breaking the rules for project cleaning in Maven. By default, "clean" will delete the target directory and its children. You should not interfere with this action. The expected action in Maven is that in most cases, if you do a "mvn clean", zip the cleaned project and email it to Ulan Bator, the recipient could easily do a Maven build where the entire project will reconstruct exactly as it did for you with no external setup or directory structure required other than an installed copy of (compatible) Maven and a JDK. If you have static resources that need to go into that product, you'd typically place them under src/main/resources (or src/main/webapp, if it's a WAR). Everything under target should be considered subject to unpredicable modification or deletion.



Thanks. This is all related to Maven. What I want to know is the difference between this and the case where we don't use maven and simply go to Project,select the project and click on clean.
 
Tim Holloway
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first paragraph answered that.
 
Sheriff
Posts: 3203
475
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:In Eclipse, I can see that one can do clean/build using two ways:
    1. Go to project.Select Clean,Select the project.
    2. Right click on the project and run as maven clean.
What is the differerence that it makes ?


As Tim said, the first option is effectively the same as running mvn clean from the command line (target directory will be gone).

The second option will however remove the compiled classes and other artifacts, but will leave the target directory in-place.  Also, by default, Project/Clean will also trigger a rebuild, which may be unexpected.

I use Eclipse + Maven everyday, but never use the IDE for any of the Maven operations.  I prefer using the mvn command-line interface.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:My first paragraph answered that.



Thanks.Understood.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:  Also, by default, Project/Clean will also trigger a rebuild, which may be unexpected.



Only in cases where "build automatically " is enabled ?
 
Ron McLeod
Sheriff
Posts: 3203
475
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:Only in cases where "build automatically " is enabled ?


No - this option in the Clean dialog:



Edit: Project/Build Automatically would probably also trigger a rebuild as well
 
Tim Holloway
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It gets a little tricky here, since the Eclipse automatic build doesn't use Maven. It compiles Java files when they are edited, and if you do like I do and set up the Eclipse project so that compiled classes go to the project's target/classes directory you get the same effect as if mvn compile had been run, but without additional help it won't do an advanced goal like "mvn war:war" would.

So if you want to clean a project and ensure it stays clean, you're better off shutting down Eclipse (or at least closing the project) and doing a clean from the command line. Not because Maven operates differently, but to keep Eclipse from meddling in the clean project.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:

Monica Shiralkar wrote:Only in cases where "build automatically " is enabled ?


No - this option in the Clean dialog:



Edit: Project/Build Automatically would probably also trigger a rebuild as well



Thanks.Understood
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one question.In which case would someone want to do CLEAN but not followed by BUILD ?
 
Ron McLeod
Sheriff
Posts: 3203
475
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:I have one question.In which case would someone want to do CLEAN but not followed by BUILD ?


I would do it if I wanted to make a snapshot of my project before doing something risky.  Backing-up non-source just makes the archive more bulky and slower to create.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Tim Holloway
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I mentioned earlier, what if your project had been outsourced to Outer Mongolia? For a developer to work on it there, a "built" project would not be a good thing. Not only is redundant information being shipped, an unclean project may be obscuring the fact that it's missing essential parts needed to build on a foreign system or has out-of-date parts. A "mvn clean" strips the project down to the source and only the source. When the foreign developer wants to start work, all they need is a suitable version of Maven, a compatible JDK, a few environment variables (MVN_HOME, JAVA_HOME) and PATH setting ($MVN_HOME/bin:$JAVA_HOME/bin or the Windows equivalent), Give that, said developer should be able to build a functionally identical - possibly even byte-for-byte identical - copy of the target without any further tweaks to their OS or filesystem.

Not only outsourcing, but many open-source projects depend on that reproducibility and ease of setup to allow multiple geographically-dispersed developers to contribute.

Note to Ron. These days, it's good practice to "git init" a source project and commit changes periodically. That also allows to do a quick branch if you're working on Version 2.9 and you get a sudden request for a quick fix on Version 2.8.17.

Of course long before Git made it possible to make small local archives without investing in the main corportate code repository, Eclipse has kept edit histories and those have saved my hide more often than I can recount. Plus you can do difference comparisons on them.

When using git (or any other version control system), I recommend adding most of the project's "dot" files to the ".gitignore" file, excepting possibly the .project and .classpath files and .gitignore itself. Git has the virtue that you can also have a separate local ignore file in a project for assorted scratch and junk files that shouldn't show up in the official archive. I also usually put target in .gitignore as well. Everything in target should be re-creatable from a mvn build so there's no point in archiving any of that stuff. If I need to archive the product, that normally ends up in my Nexus Maven repository server anyway and Maven publishes it there.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:A "mvn clean" strips the project down to the source and only the source. When the foreign developer wants to start work, all they need is a suitable version of Maven, a compatible JDK, a few environment variables (MVN_HOME, JAVA_HOME) and PATH setting ($MVN_HOME/bin:$JAVA_HOME/bin or the Windows equivalent), Give that, said developer should be able to build a functionally identical - possibly even byte-for-byte identical - copy of the target without any further tweaks to their OS or filesystem.



Thanks.That perfectly is what I wanted to know.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have so often sent my code to someone or transferred from one machine to another machine but this never striked me that why not clean the project and send ,thus transferring smaller size faster.
 
Tim Holloway
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I once worked in a shop where another department had developed their own primitive ORM system and we were commanded to use it.

We couldn't. They made certain assumptions about what was installed on the OS and their directory layout schemes were in direct conflict with ours. One of the things I live about Maven and its relatives is the elimination of these issues.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:. One of the things I live about Maven and its relatives is the elimination of these issues.



All I was knowing was that all maven does is create Jar/War with dependencies. Does creation Jar/Was with dependencies involve those issues too ?
 
Tim Holloway
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two types of "dependencies" here. The type that Maven fixes is dependencies on third-party (project external) libraries. It does that by automatically fetching and caching those dependencies from external repositories and retrieveing them when needed. It also uses the same basic mechanism for managing external components that you've created locally, which makes things even tidier.

The type of dependency that Maven cannot fix is when your project requires certain resources to be located in certain specific directories external to the project and on certain specific machines. That's what I had to deal with when we were using Ant to build stuff (and didn't even have Ant Ivy at the time).  Having that sort of mess means spending a lot of time re-arranging how your computer's file system is set up and in many cases - including ours - can conflict fatally with how we were set up to do our locall-developed projects.

A proper Maven project requires nothing external to the project itself except for Maven-fetched dependencies, and since Maven does the fetching doesn't require a specific filesystem layout.
 
Monica Shiralkar
Ranch Foreman
Posts: 1770
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
There's a city wid manhunt for this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic