For running Java main application in Eclipse, how to exclude test-classes in classpath? - eclipse

I am running a Spring Boot application (java main function) in the eclipse. It is a maven based project. I think eclipse uses m2e plugin to run it. But every time I run my project, the test-classes folder is added to the classpath in the final command.
I have to manually remove the test folder (src/test/java and src/test/resources) from source folder in all sub-projects. But when I right click the project, Maven -> Update Project... , the test folder be added to source folder again automatically. Then the final test-classes folder be added into classpath for the run command.

In current Eclipse version there is a checkbox "Exclude test code" in Dependencies tab to exclude src/test sources.

Related

How avoid Eclipse load test-class file in to classpath when Java app run?

I am using STS to develop a large Spring Boot based application. We have multiple maven projects and a parent project to include them all. Each project has own testing code and config files.
When I run the Spring Boot application in the main entry class. The test-classes folder of the depended projects will be loaded into the app running classpath, that causes some conflict of spring bean definition. I have to config every project removing [src/test/java and src/test/resources] from the 'source folders on build path'.
The whole project structure is like below:
app-parent
sub-app-1
sub-app-2
sub-app-3
main-app [running from this project]
main-app project has dependencies on the sub-app-1 ~ 3.
Is there any way to let STS (Eclipse) run a Java App excluding the test-classes folder from classpath? I really do want the testing code under source folder but not have them when the App run.
Besides, I tried open the [run configuration], but it can only add more file to the classpath.
As pointed out by #torsten-crass, verify that Exclude test code is ticked in your Classpath tab of Run configurations in Eclipse.
Here is the screenshot.

class test in an existing project j2ee converted to maven project

I'm a beginner in Maven and i have to "mavenize" an existing project for a company.
I opened the project in Eclipse and right click on the project -> Configure -> Convert to Maven Project.
So after that I didn't get the folders : src/main/java, src/main/resources, src/test/java, src/test/resources. I didn't get anything.
I have the m2e plugin and also Maven 3.3.3
I get the lib and Maven Dependency and arrange the pom.xml but i didn't have any test folder and any class Test so when running mvn:test i get no tests to run.
My question is : I have to create all the classTest manually ? Or Maven is supposed to create them automatically ?
Convert to Maven would normally:
configure the Maven Compile Plugin according to the JDK version in use by the original project
configure the build/sourceDirectory element (normally to src) instead of the standard src/main/java
ignore the bin folder used by default by Eclipse (so may see it in the Package Explorer and you can safely delete it)
Some manual steps are required (and suggested):
move the code to a newly created src/main/java folder and remove the build/sourceDirectory customization
remove the bin directory (it will now be target/classes)
Create src/main/resources folder and move any required resource (configuration file, etc.) to this folder
place your test sources under src/test/java, which you also need to create
if not the case, rename any test class to end by the *Test or *TestCase suffix so that by default the Maven Surefire Plugin will pick them up automatically (if not possible, alternatively you would need to configure it as described via official documentation here
If you don't have any test class yet, of course Maven would never create them automatically, you are responsible of writing your test cases, Maven would only run them.

How to adjust Netbeans' "Project Files" filter

I am working with a NetBeans project with Maven which uses the Maven assemble plugin. That plugin is configured via a file assemblePlugin.xml which is in the root folder of the project, just like the pom.xml.
But when I look at the project in the Projects tree, the folder Project Files only shows pom.xml, nbactions.xml and nb-configuration.xml, but not my assemblePlugin.xml.
Edit: logging.properties is another candidate I keep missing.
How can I adjust that filter (or turn it off)?
(Netbeans 8.0.2)

Maven project is in a subfolder, can't get Eclipse integration to work

Inside the folder 'ProjectName' exists several subfolders, and of them contains java program:
ProjectName
Specifications
JavaCode
Gfx
...
JavaCode folder contains pom.xml.
I have installed m2eclipse (0.10.x) to Eclipse and imported whole ProjectName folder to Eclipse. Subfolders are displayed correctly but maven integration is not working correctly - for example I don't see src/main/java "shortcut" folder in Eclipse, but I have to click to open all folders.
If I create a new maven project with Eclipse from scratch, the integration works well.
What could be the issue?
Select the JavaCode folder and then invoke File... / Import... / Maven Project. That would bring your Java code into Eclipse as a proper project with Maven support enabled. It is fine to import several overlapping folders. So, you could use the parent for version control purposes and JavaCode would be the actual Java project you'd work with in the IDE.
Unfortunately there is no way around that, unless you want to move your pom.xml to the root project and remap all the Maven plugins to folders under JavaCode project. But that would be really bad idea and Maven integration for Eclipse may not work with such project structure without an additional tweaking.

m2eclipse : Maven dependencies as JAR's not projects

I'm having maven project on Eclipse with m2eclipse plugin. This project has some dependencies. Some of them are libraries as slf4j, apache-commons etc. But there are also mine libraries, that I'm developing simultaneously in eclipse. Unfortunately m2eclipse creates build path in such a way that my libraries are added to the classpath not as a JAR archives from M2 repository but as class files from /target/classes directory. For that reason I can not use maven-shade-plugin beacuse I'm gettin a message:
" Error creating shaded jar: error in opening zip file /home/user/workspace/my-project/project-a/target/classes".
When I'm building project-a from command line using mvn clean install everything works well - shaded JAR is generated. How to fix it?
After few hours of searching I've already found solution. This can be made by configurinng Maven Build Configuration
1. Select arrow on Run as.. button
2. Select Run configurations...
3. Select yours project Maven Builder
4. On the right tab (Main tab) deselect: Resolve Workspace artifacts.
Click Apply and build your project - all will work as you wish :).