Can I use or import an Eclipse formatter in NetBeans? - eclipse

We have been using Eclipse for a long time. We have formatter for each of our projects. Now, some of us are moving to NetBeans. Is it possible to migrate / sync / import our Eclipse formatter to NetBeans? I tried importing an Eclipse project into NetBeans. It does not import the formatter we used.

The answer is YES. You can use eclipse code formatter in Netbeans, and enjoy using Netbeans. You need to download eclipse code formatter plugin from below location suitable to your Netbeans version, import your existing eclipse code formatter and ready to go
http://plugins.netbeans.org/plugin/50877/eclipse-code-formatter-for-java

AFAIK There is no way to import the Eclipse formatting preferences into NetBeans.
But if you use Maven you can use the Maven2 Java Formatter Plugin which uses the Eclipse JDT features to format source files and integrates nicely with Maven projects. For a usage of current version 0.3.1 see here.
This is a simple pom.xml using the formatter. Just put in any Java source file and run mvn java-formatter:format, your source should be formatted using the given Eclipse configuration file (where you have to provide the path to your own one).
<?xml version="1.0" encoding="UTF-8"?>
<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>de.mackaz</groupId>
<artifactId>maven.java.formatter.plugin.example</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
<artifactId>maven-java-formatter-plugin</artifactId>
<version>0.3.1</version>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
<configuration>
<configFile>./example-eclipse-code-format-config.xml</configFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
EDIT:
A different approach is to invoke the Eclipse Code Formatter from commandline, (but takes a bit longer and is not nicely integrated into the Maven lifecycle), as described here.
You can format a sourcefile with it like this:
/opt/eclipse/eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -nosplash -config example-eclipse-code-format-config.xml src/main/java/de/mackaz/FormatMe.java
(Also take a look at this page where the author put that into a little script)
It should be easy to integrate one of those approaches into NetBeans. Either wrap those inside an Ant file and add that to your NetBeans commands, or write a little NetBeans plugin to add the action e.g. to the contextmenu (which is pretty easy, especially compared to writing Eclipse Plugins).

I like NetBeans very much, but have the same problem with formatting.
I've found this maven plugin http://mvneclipsefmt.sourceforge.net/usage.html
Seems it can run eclipse formatter as maven goal. But I didn't try it yet.

There is a post on JBoss community which seems to address formating issues, it might be of some help; http://community.jboss.org/wiki/ImportFormattingRules

You can use "Eclipse Code Formatter for Java" NetBeans plugin it works with NetBeans 7.3 and .7.4 (but with a little problem!).

It would appear that, as of Netbeans 7.3.1, a very clever fellow developed a Netbeans plugin that accepts Eclipse Formatter XML files. I have not tested this yet TBH, but I will be doing so in the very near future (as I am the only one at the office that prefers Netbeans over Eclipse, and I think my co-workers are conspiring to kill me due to git merge conflicts).
https://blogs.oracle.com/geertjan/entry/eclipse_formatter_for_netbeans_ide

It should be easy to use Eclipse's formatter as a plugin in Netbeas, like it was done for IntelliJ

The following link may be of assistance http://netbeans.dzone.com/articles/importexport-code-formatting it talks about sharing sharing settings.

Related

Eclipse 3.7 (indigo SR2) m2e (1.1) import Maven will not add source folders of generated sources

I have a larger Maven (3.0.4) project which contains modules which have generated code like jaxb, javaws etc.
The problem I have is that after importing the projects the generated source path is not added as source folder in Eclipse. Currently i need to add the folder (target/generated-sources/jaxb) manually to get it working in Eclipse.
In older versions of m2e there existed a configuration which controls the phase which is run during the import.
Does someone have an idea which has to be changed?
Update
I have tested to add the source folder via the build-helper-maven-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/jaxb/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
But this doesn't solve the problem neither.
You need the m2eclipse-buildhelper plugin to let m2e know how to add the new source folders.
If the version from
Window > Preferences > Maven > Discovery > Open catalog...
doesn't install, try using this p2 update site to install it instead :
http://repository.tesla.io:8081/nexus/content/sites/m2e.extras/m2eclipse-buildhelper/0.15.0/N/0.15.0.201207090124/
Other than putting maven-controlled dependencies in the class path Maven seems to have backed away from updating project configurations. This means that if you have Eclipse tools that require special project natures or class path configurations you will have to make those configuration changes yourself (or hope the tool does).
To support this m2e has added two eclipse extension points that an Eclipse plugin can extend. These extensions will be called when the classpath and project description are being updated by maven. And they're called only if you write an eclipse plugin that can be called.
There's a lot more detail, but that detail requires and understanding of eclipse plugin development.

Eclipse not picking up Maven attached source on debug

I've downloaded the source for all the Maven JARs in my buildpath using Maven->Download Sources and mvn eclipse:eclipse -DdownloadSources=true, which worked! When I open up the build path I can see that the sources JARs are attached for every JAR file.
But when I run the damn thing on Tomcat 6 I keep getting "Source not found" page with "Edit Source lookup path" button. But the source is already attached in the build path. What isn't this working?
When I manually point it to the JAR file by clicking on the "Edit Source lookup path" button it works. And when I manually point it to the folder it does not work. Why isn't Eclipse or Tomcat picking up the attached source in the build path?
Note: I'm using apache-maven-3.0.4, apache-tomcat-6.0.16 and Eclipse Indigo Service Release 2.
Although this bug had the most votes of all bugs #Sonatype, it hasn't been fixed.
However I have filled an enhancement request on Eclipse Bugzilla and if you agree this issue "Source not found" should be fixed, please vote for it here.
You can found three workarounds here.
I found this com.ifedorenko.m2e.sourcelookup plugin. The link was provided in "Java Debugging: Source not found".
Go to Help > Install New Software .. and use
http://ifedorenko.github.com/m2e-extras/
to search for the links. After installing this plugin I was finally able to debug the source code of dependencies.
Use External Maven instead of default Embedded in Debug Configurations dialogue.
Please see example screenshot below (menu Run -> Debug Configurations...):
Configure external Maven
Tested environment:
Eclipse IDE for Java Developers: Oxygen.1a Release (4.7.1a), 64-bit (from spring.io)
Oracle JDK jdk1.8.0_144, 64-bit
Maven: 3.5.2
OS: Windows 10 Enterprise N, 64-bit
Test goal hpi:run (sample Jenkins plugin)
Window->Preferences->JBoss Tools->Source Lookup
make sure you have check "Automatically add the JBoss Maven source container to all JBoss As launch configurations".
and under "Automatically configure the Java Source Attachment",
choose "Always".
this helps myself out of the problem.
In my case the problem was related with the source code attached with the "Debug Configuration", maybe some remnants form a migration to Maven.
I solved it by going to the "Debug Configurations..." page and selecting the configuration in case, then at the "Sources" tab I restored the defaults, which added all the project's Maven dependencies.
I think I fixed this for myself by updating my Eclipse m2e.
I think I had version ~1.2, and then updated to latest [as of writing] 1.6.2.
The Eclipse Bug comments helped me figure this out.
Now I can debug into my gquery-dnd-bundle-1.0.6!
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${version.maven-source-plugin}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
The "target" maven project should emit it's source code before the "client" projects can have access to the source code. I solved the issue by using the maven-source-pluging in the "target" project: https://maven.apache.org/plugins/maven-source-plugin/index.html
Just use the following snippet in the pom.xml file of the target project, make a release, and use the release version into the pom.xml file of the client project. Then eclipse can automatically let you "jump" to the target project seamlesly:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${version.maven-source-plugin}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

Error when importing Maven-GWT project ("No marketplace entries found to handle gwt-maven-plugin")

I'm using Eclipse Indigo on Win XP, Maven 3.0.3 and GWT 2.4. I created a Maven-GWT project using the Mavne gwt archetype. Then I opened Eclipse, went to File -> Import, selected Existing Maven Projects, chose the pom for my GWT-Maven project, and then got this dialog:
The errors are
No marketplace entries found to handle gwt-maven-plugin:2.4.0:generateAsync in Eclipse. Please see Help for more information.
No marketplace entries found to handle gwt-maven-plugin:2.4.0:i18n in Eclipse. Please see Help for more information.
No marketplace entries found to handle maven-war-plugin:2.1.1:exploded in Eclipse. Please see Help for more information.
Anyone know how to resolve these errors? It is wreaking havoc when I actually import my project and try and work with it. - Dave
Make sure you are not using the embedded Maven of Eclipse.
Go to Window->Preference ->Maven -> Installation->choose your own maven installation folder there.
EDIT
If your company pays for IDE, you should ask for IntelliJ the IDE for Java, which I would say is better than Eclipse in many ways, not saying Eclipse is not good, that's just a good alternative. And you won't have this issue to start with
If your pom is not specific as to the version of the maven-resources-plugin, that version will come from the superpom. By default, m2e uses an embedded copy of Maven 3.0.x. If the superpom there points to 2.4.3 and your 'outside-of-Eclipse' version asks for something else, then the Maven inside of Eclipse will go looking for 2.4.3 and fail due to the 'offline'.
Fix by configuring m2e to use the Maven installation you are using outside, or turning off 'offline' for one build.
If you want to use maven from your local installation instead of the embedded version that comes with m2e, You have to do this
Windows ==> Preferences ==> Maven ==> Installations ==> Click Add (select your local maven installation directory)
Installation Directory is not where local repository. It is where maven is installed.
After changing try right click on project then,
Maven ----> Update Project
See How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds
You can basically just copy the snippet from http://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven#POM_changes_needed_for_Eclipse_Indigo and adapt to your plugins and goals.
I am using a different approach with maven, gwt and eclipse.
I am using the maven eclipse plugin to generate a .classpath and .project file and import the project manually into eclipse (not as a maven project).
My configuration for the maven eclipse plugin looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<buildOutputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</buildOutputDirectory>
<projectnatures>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
<projectnature>com.google.gdt.eclipse.core.webAppNature</projectnature>
<nature>com.google.gwt.eclipse.core.gwtNature</nature>
</projectnatures>
<buildcommands>
<buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
<buildcommand>com.google.gdt.eclipse.core.webAppProjectValidator</buildcommand>
<buildcommand>com.google.appengine.eclipse.core.projectValidator</buildcommand>
<buildcommand>com.google.gwt.eclipse.core.gwtProjectValidator</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>com.google.gwt.eclipse.core.GWT_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<exclude>com.google.gwt:gwt-servlet</exclude>
<exclude>com.google.gwt:gwt-user</exclude>
<exclude>com.google.gwt:gwt-dev</exclude>
<exclude>javax.validation:validation-api</exclude>
</excludes>
<linkedResources>
<linkedResource>
<name>war</name>
<type>2</type>
<location>${basedir}/target/${project.artifactId}-${project.version}</location>
</linkedResource>
</linkedResources>
</configuration>
</plugin>
Hope that helps
This helped me:
Delete the project from eclipse (but don't delete from disk)
Close eclipse
In your user folder there is .m folder.
Delete repository folder underneath it (.m/repository).
Open eclipse Import project as existing maven project (from disk).

m2Eclipse plugin with maven 3.0.3, no compilation errors, and jre5 with jdk7

Question about the m2 eclipse plugin. Currently I have "Eclipse Java EE IDE for Web Developers", the most recent update. I have the m2 eclipse plugin installed, and have started a normal java project. I then converted this to a maven project via
"right click->configure->convert to to maven project"
This appears to work, a pom.xml is created, the project converts, and everything is well and good.
The issue starts when I do anything to this project. In the maven settings for the project "Right client on project -> maven" there are several options that are behaving strangely, updating maven configuration will change the default JDK for the project (JDK7) to j2SE-1.5..., which was never installed on the machine, and of course is not found. Also code completion, and and error checking is not working in the editor.
Example:
params.put("some_string", ); This should render "red" for compilation errors because there is no second argument to put(), however this checks out as okay according to the eclipse editor.
I have some done some research on this issue, and from what I can gather from Google, it appears that there are some issues with m2eclipse and this distro of eclipse however there is nothing to resolve this. Is anybody else having similar problems, or does anybody have any idea how to resolve this?
Please let me know if the is any other information I can provide, I didn't want to just paste my settings.xml into stack overflow.
Note: I have my settings.xml configured in Eclipse, and have specifies which jdk to use (7)
System information:
Maven version: 3.0.3
Eclipse Version: Eclipse Java EE IDE for Web Developers Version
All eclipse plugins have the most recent versions installed as of this post date, and there are no XML integrity errors, or anything of the sort.
For the JDK issue: in your pom.xml specify
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
and then do another "Update Project configuration". Then the JDK 7 should be set (at least works for me).
Okay, so the answer to this is the answer to so many other questions on Stack overflow and other sites.... "mvn eclipse:eclipse". I was under the impression that Eclipse "did this for you" on project startup, and that is apparently not the case. After running that on a brand new work-space after an eclipse re-install (new computer) everything works fine.
I felt the need to close this one out. Thanks for the help though.

How do I make the Eclipse Checkstyle plugin and the Maven Checkstyle plugin use the same rules?

I'd like the Checkstyle rules in Eclipse match the rules when my Maven build runs on Jenkins.
How do I go about that?
Thanks.
[edit]
So I exported the checkstyle settings in eclipse to a new XML file in the project folder and pointed the maven checkstyle plugin at that with
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.6</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
You will have to export your eclipse checkstyle settings into a file and configure your Jenkin (/Hudson) checkstyle plugin to use the same configuration file.
I did it as followed: I have a separate maven build project that contains checkstyle/pmd and others stuff (rule sets) on the classpath.
Add this project as dependency in the checkstyle/pmd plugin configuration in your pom, and it will work in maven and in jenkins/hudson if you simple call the maven checkstyle/pmd goal.
Works like a charm.