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

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.

Related

Gradle Multiproject War withEclipse gradle plugin. Not including project dependencies in tomcat webapp/app/WEB-INF/lib

In a gradle multiproject, I have 3 projects:
The first one contains basic utils (plugin; java-library)
The second is a java application that depends on the first project (plugin: java)
The third is a web application, that depends on the first project (plugin: war)
All 3 projects are declared in settings.gradle of the parent project
The first project is referenced from the second and third project setting:
api(project(":FirstProject"))
The second project runs without problems from Eclipse (Run As- Java application)
The third project cannot run properly as has missing dependencies at run time (Run As - run on server)
Looking in the directory where local tomcat resides in eclipse
/home/ximo/WORKSPACES/WS01/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/CSV01/WEB-INF/lib
I have detected that the first project jar is missing (firstproject.jar)
But when executing the build task from the "Gradle tasks" view, the generated war does contain the "missing" jar.
So the problem only arises when Eclipse deploys the application to the local tomcat for running (or debugging) locally the application.
I have used 2 possible "dirty" solutions for this problem:
Copying this jar by hand to the referenced deployment lib folder.
Adding to the build.gradle a reference to the missing jar
implementation files('path_to_jar/firstproject.jar')
Any idea for solving this issue?
Thanks.

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

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.

JBoss 6.1.1.EAP Module Deployment: Class not found

The structure is as follows:
Actually deployed module is EAR.
EAR contains WAR module, and WAR module contains another JAR module.
In this last JAR, there are some generated classes and their parent folder is also used as source folder. Its path is "target/generated-sources/java".
The problem that is killing me, is that the deployed application throws ClassNotFoundException on server start, and the classes in question are the generated ones.
Now the trick:
if I explicitly change the Deployment Assembly in WAR project in Eclipse not to contain JAR project as "project", but as an archive from the JAR's project "target" folder, JBoss sees the generated classes and starts.
This solution however works only until next eclipse maven project update, so manual edit of deployment assembly is not really a solution.
Any ideas how to deploy or reorganise packages correctly?
OK, seems I have found the solution.
I looked through the build-path of the mentioned JAR file and saw that the entry Output folder pointed to target/test-classes.
After changing this entry to target/classes the application deploys and starts without any missing generated classes.
This is what worked for me:
Expand the 'target' folder of your maven project inside Eclipse (Project Explorer View);
Refresh it (F5);
Right click on your project on 'Servers' tab, then select "Full Publish";
Start your JBoss.
I had to enforce the JBoss Tool "Full Publish" to get an updated version of my target folder by Refreshing it manually on eclipse.
I don't know why but sometimes the Publishing from maven projects (even Full Publishes) do not copy classes from the target Project as it is in the file system. Maybe it's using some outdated memory info or some cache...
Anyway, this is what works for me.
After an update to Eclipse 4.15 and JBoss tools I got this problem too.
My solution: project -> properties -> Java Build Path --> Source
There my Output folder from my source was linked to project/target/classes, I changed this to project/target/project-projectversion/WEB-INF/classes
When I looked into the standalone JBoss folder I saw the folder structure of my source, but the classes where missing, when I changed the output folder the classes pop up and everything worked like before.
I am pretty sure the update made the problems.

ClassNotFoundException when using User Libraries in Eclipse build path

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.

Grails Project - Common Java Project Dependency in Eclipse

All,
We have standard java projects that contain our common data model, common util classes, etc...
What I can’t seem to figure out is how, to make my Grails project (in Eclipse) have a dependency on the other standard (non Grails) java project in the workspace. When I add the project in the “Java Build Path” the project doesn’t show any compiler errors, but it when I run “Grails Tools -> Refresh Dependencies” or attempt to run the project (run-app) it fails.
This seems like it would be a pretty common thing, but I have searched all over the web and have been unable to find a solution. We are not using maven in our environment. Since we build Eclipse RCP applications on the client side, we use OSGI manifests to manage our project / bundle dependencies.
You can use linked source directories to include the Java or Groovy dependencies in the grails project and you need to set the output directory to Project/target/classes (these configurations go into the grails project preferences in Java Build Path options -> Source Tab).
The change in the output directory allows Eclipse to detect changes in the dependencies and auto load it when running the app using grails run-app.
You can use autocomplete and debug the sources of the dependencies with this configuration.
I prepared a step and step process that includes screenshots for Java and Groovy here
The documentation includes information on customizing the build.
You can add this to your BuildConfig.groovy:
grails.compiler.dependencies = {
fileset (dir:"/path/to/jars")
}
That should get you started.
If the dependencies are not stored in an Ivy/Maven repository then AFAIK your only option is to copy the dependencies to the lib directory of the Grails project.