Question: When running Maven in Eclipse, how do I send the console output to file?
I would like to achieve this using a pom setting or a maven plugin. I do not want to modify the run configurations or the maven system settings.
For reference, I am using Windows 7, Eclipse Luna, Java 6, Maven 3.
As per official command line options you could use -l,--log-file <arg> which provide the:
Log file where all build output will go.
As such, running:
mvn clean install -l output.log
Would not print anything to the console and automatically redirect the whole build output to the output.log file.
If you don't want to type it every time (or you actually don't want to use the command line) and you want it as default option (although rare case I would suppose), you could use new command line options behavior available since version 3.3.1 and have a .mvn folder where the concerned pom.xml file is located and a maven.config file in it simply providing the following line:
-l output.log
That is, the .mvn/maven.config file replaces MAVEN_OPTIONS just for its project, locally where it has been created, with the options it provides, not impacting other builds as per Maven settings of MAVEN_OPTIONS.
This is an IDE agnostic solution (it's a new built-in feature of Maven) and local to a project, but still not provided via simple POM editing, which cannot be achieved since the first phase of Maven default life cycle phases is validate, which:
validate the project is correct and all necessary information is available
That is, during the build, hence when the build has already started (and generated output), it validates the pom.xml file, hence too late to redirect build output at that stage based on some POM properties/plugin.
Go to run as and choose Run Configuration -> Commons -> Select a file.
This should redirect your output to the file you specified.
According to this you can try editing the ${MAVEN_HOME}/conf/logging/simplelogger.properties. I gave it a quick try and maven's output is redirected, but anything else writing to stdout (tests, for instance) still writes on the console
What about creating a fork of M2E and modifying it to read the output file for the launch config from pom.xml
https://github.com/eclipse/m2e-core.git
A possible solution is setting the output format in the mvn file. For example, in the directory /usr/bin, add the desired output informing the path the log will be saved at the end of exec "$JAVACMD" \ line: | tee /home/maven-log.log.
However, it only works when the maven is called by terminal line; when called by IDEs, like eclipse, this solutions does not work.
Related
In my maven project I usually use the POM file named pom.xml. I have a second POM file though (call it pom_alt.xml), which I occasionally use to perform a very different build of the same project. To do so I specify the -f option in the command line
mvn clean package -fpom_alt.xml
as suggested by man mvn:
-f,--file
Force the use of an alternate POM file.
Now, when I am coding in eclipse I usually need maven to use pom.xml, but sometimes I should code or debug while the other file pom_alt.xml is used instead. Is there a way to tell the eclipse maven integration to use that file? Currently I am temporarily copy-pasting from pom_alt.xml to pom.xml since I seldom happen to need that, but you can see that's not optimal.
I am with Eclipse IDE for Java EE Developers, Mars Release 4.5.0.
UPDATE
I could build from the command line or use Run As Maven build as in
Carlos Andres' solution, but ideally I would like to define a persistent setting, like a property or preference. This because I find nice if the POM file can be fixed while I am doing things like running as Java Application and test cases, or executing on a server. Processes that require a project clean or server restart are often triggering a maven build with the default POM.
Check that M2E - Maven Integration for Eclipse is installed on Eclipse. Once that is installed go to the project and press right click
Next, put the command that you want to execute
This option allow you to save the commands, and the next time all your commands will be saved.
To execute the command recorded go to
I have a selenium project in eclipse that i want to distribute to manual testers with no Eclipse or Java knowledge. Hence i am looking to distribute it to them as executable files so that they dont need to use eclipse to run them. Can any one suggest the best way to do this without having to install any 3rd party extensions?
P.S : My organisation doesnt allow me to install 3rd party extensions on Eclipse. It will require a lot of approvals. Hence i am wondering if there is any method available inside Eclipse itself?
I've done it some years ago, in my eclipse version:
file -> export -> java -> Runnable jar file
If you want an exe file you can use: Launch4J
Export your project as jar file and create a .bat file which will include all the necessary libraries in your classpath with your project and then make a call to the underlying script (in case if you are using testng then testng has option to make command line calls)
else use Maven
EDIT:
Something on below lines:
1. Create run.bat file
2. Content of the bat file:
JAVA_HOME={Path to your JDK}
CLASSPATH=%PATH%;{All the dependent jar files of your project as well as you project}
{Call to your Junit Script from command line} Something like this Run JUnit from command line
3. Run your batch file (run.bat)
I may not have provided the exact code but thats where you should be heading if you wish to run your JUnit tests from command line.
NOTE / FYI : Maven does not require any installation or approval..You just download the zip and unzip it and set environment variable and thats it.
I never had to do this before but maybe someone else has.
I want to run "mvn --encrypt-master-password".
I'm on a machine with only Eclipse and m2e. I could of course download and set up maven on my hard drive with the appropriate JAVA_HOME envvars etc, but I figured I'd try to get it done quickly in Eclipse.
m2e quickly gives a "no goals have been specified" error.
I could put in a dummy goal but I can't see any way to enter a mvn command line parameter (as opposed to a 'goal parameter')
This is theoretical now since I'll go and do this on a command line somewhere, but I'd like to know if it's possible.
For a one-time password encryption job you can set --encrypt-master-password <your password> as a goal in the Maven build as already specified by flafoux (Run Configurations > Maven Build > New build > ...).
But this is not secure since you password is stored in a configuration (unless you delete it right after the execution). And this is also not handy since you need to update a job manually for every encrypted password you need...
ps: https://maven.apache.org/guides/mini/guide-encryption.html says since 3.2.1 Maven should ask for the password if not specified, but it does not at least at my eclipse lune having Maven 3.2.1 embedded - may be it does at more recent verions.
You can set goals with build configuration.
Create a maven build configuration (Run as > Run Configuration... Maven builds , and add goals.
more explanation : http://books.sonatype.com/m2eclipse-book/reference/running-sect-running-maven-builds.html
I ran it in cmd and it said no main manifest attribute in, JGame2.jar
how do i show it where the main is?? it works fine in eclipse.
For
java -jar x.jar
to work, the jar file must contain a META-INF/MANIFEST.MF file, and this file must contain an entry for the main class. You can add a manifest in Eclipse. Note that any dependencies must also be accounted for, either by:
a class path in the manifest
-cp on the command line
use of some tool to combine to one jar
Eclipse is just an IDE, you might consider learning to use an actual build tool such as Maven or Gradle or Ant to allow you to repeatably build usable results.
I have a project in eclipse right now that is compiled using ant. I am wondering what eclipse is doing behind the curtains whenever I double click on the jar target of one of this build files.
Is it possible to get the commands that eclipse is executing with ant, as I'd like to setup a shell script that compiles the project. How can I find what commands it is actually executing and what parameters it is passing.
I imagine there are also some variables like classpath, and buildpath that are set, where do I find them as to be easily copied over.
Eclipse comes with its own installation of ant. Is it possible to use that bundled installation of ant to build via command line.
Any help appreciated,
Ted.
One possible way is to look at the process executed by Eclipse when building.
For that, use Process Explorer (if you are on Windows) in order to display the full command line and all its parameter when running that build.