How to set up project references Eclipse - java

I have a web project in my workspace that has a dependency on a java project in the workspace.
In project references, I made my web project reference the java project, but there are still build errors that indicate that classes in my java project are not referenced by my web project.

An Answer
This is not a direct answer to your question, but is an solution to the problem you are experiencing.
The java project must be deployed for your web project to run in any environment other than you eclipse debug environment. I assume that the deployment technique is a JAR file.
Build the java project. That is, produce the deployable jar file. I will call this the XYZ.JAR file.
Put the XYZ.JAR file in the /WEB-INF/lib of your web project.
Possible answer to your question
Check the following, I suspect your answer lies therein:
Is the JDK Compliance of the java project different from the JDK compliance of the web project? Higher on the web project is fine. Lower on the web project will not work.
Did you build the java project?
Is automatic build set for the java project. I suggest that you sould set auto build.
Try running a clean then a build on the java project then the same on the web project.
You say dependancy. Do you mean that you added a reference to the java project in the Properties!Java Build Path!Projects tab of the web project? If the answer is no, then you should add one. Note: this is fine for compilation, but in no way helps once you deploy.
Have you setup an EAR file with which to deploy the java project and the web project (not applicable if you are deploying to a servlet container such as Tomcat)? If yes, then add a reference to the java project in the Properties!J2EE Module Dependencies of the web project

Related

Create a Gradle 7.x Java web application project in Eclipse 2021-03

I use Eclipse and Gradle for a few "desktop" / command line Java application projects, including multi-project projects.
But I haven't used Gradle for a Java web application project in Eclipse so far. My usual approach is:
Create empty workspace and configure it (JDK, Runtime environment Tomcat server)
"Create a Dynamic Web project", run through wizard
And everything works fine. The project has a proper structure (WEB-INF exists, web.xml is created etc.), it compiles and it is deployed automatically to Tomcat by Eclipse. CATALINA_BASE is set to some temp folder in the workspace.
But how do I create a Gradle project which is a "Dynamic Web project" and not just a command line Java application or java-library?
I have tried two approaches:
Create a Gradle project using the wizard in Eclipse. It seems to create a java-library project always with a lib subproject. Having created the "wrapper" project and the actual Gradle project lib, set java and war as plugins for this. Open the project properties of the Gradle project lib, Project Facets, add Dynamic Web Project Facet (4.0). Create run configuration to make it run in Tomcat server.
Create a Gradle project using gradle init in an empty directory. Create application project instead of library. Import that existing Gradle project into an empty workspace (instead of using Eclipse to create the project). And apply the same procedures as above (facet etc.).
None of the approaches gave me a working, ready-to-use web application project that has the expected folder structures (WebContent, WEB-INF, ...), that deploys correctly (no deployment or e.g. web.xml missing) ...
I spent several hours to use Gradle in a Java web application project in Eclipse. (Because I want to profit from its easy declarative dependency management.) But I didn't manage to make it work.
Also the samples in the Gradle docs do not contain a Java web application project:
https://docs.gradle.org/current/samples/index.html
Only Java Application or Java Library.
Has someone else already managed to set this up?
Gradle 7.0.x
Eclipse 2021-03
Tomcat 9 or 10 (I've tried both)
AdoptOpenJDK 11
Windows machine
Please share your approach. :)

Eclipse build automatically to do maven build?

I have my main web application(has its own POM) that is dependent on module A((has its own POM).
When i make a build using mvn install on web application, it dependent modules
are also built in to jar file and ultimately included under WEB-INF/lib folder of main web app.
But that does not happen in when i make build using eclipse kepler (containing both maven projects i.e main web app and its dependent module A).
When building with eclipse, it just put the modified classes under moduleA/target/classes/ folder but does not make any updated jar file and put it
under WEB-INF/lib folder of main web app.
Is there a setting where i can configure eclipse building the project same way as maven does (which will really save lot of time and help in hot deployment) ?.
It used to work in one of my projects looks like some configuration is required for this.
looks like m2e connector(i have SonarQube) needs some configuration to make eclipse build in the same fashion as maven build
When i do the project > right click > mvn install , i am able to make jar file.
But what i want is eclipse build automatically option do
the build for project/module wherever modification is done , construct the jar and include it in parent WEB-INF/lib folder if it is dependent module ?
Assuming you're using the Java EE flavour of Eclipse, you can easily deploy Maven based web applications to a local server (like Tomcat, Wildfly...) from the server view.
m2e-wtp, included in recent Eclipse Java EE distros, takes care of configuring all Eclipse settings based on your project pom.xml configuration and dependencies.
See this screencast to see how simple it is : https://www.youtube.com/watch?v=TksoKkSP208
For the record, deployment/publishing is performed by each server adapter differently. They're responsible for publishing the proper jars under the WEB-INF/lib folder of the deployed application. Dependent jar projects are automatically zipped and deployed to WEB-INF/lib without user interaction

AppEngine Dynamic WebProject - Ear libraries not copied to War Project Web-INF/lib folder

I have a Ear Project which includes two Appengine Dynamic Web Project and one shared java project (which has common classes).
I have added shared java project to EarContent Folder through Deployment assembly settings in EAR Project and i can see the java project jar file in published folder under EarContent folder.
Now i wanted to use the Ear library in Dynamic Web Project, so i have added this library in MANIFEST.MF setting for both the project and at compile time i can access the class from shared project too.
The problem is when i publish it, i couldn't able to find the java project jar in Both Web Project, i have tried almost every settings but nothing was helpful.
Am using Eclipse Mars, AppEngine SDK version 1.9.10,
Does any one tried this, is there any possible solution for my problem. any thoughts or suggestion is highly appreciated.
Thanks!
It looks like the Google Plugin for Eclipse doesn't recognize anything in EarContent/lib (or whatever your EAR library path is) regardless of settings when packaging the WAR files for each Dynamic Web Project. The JARs need to be physically present in WEB-INF/lib for each Dynamic Web Project in order for the modules to deploy properly.
I would recommend opening a feature request in the official issue tracker here:
https://code.google.com/p/googleappengine/wiki/FilingIssues

Why can't I step through library code when debugging a web project in Netbeans?

I have a Spring MVC web application where the majority of the code I am interested in sits in two Maven projects - one being the war project and another being a jar project on which the war depends. They also share the same parent pom though that is probably irrelevant for this question.
When I try to debug my web project I can't step into any of the code from the jar. I've checked Windows->Debugging->Sources and the jar project's source directory is present there. Both projects are open. Does Netbeans 7.0 not support stepping through a web project's dependencies?
In your library manager screen, in your sources tab, have you provided the location of the source folder.http://wiki.netbeans.org/AttachSourceToLibrary.
When you are stepping in to class files ( that netbeans could not find source far), there usually is a prompt from Netbeans asking if you want to associate a src with this corresponding file. Either way, I have managed to step into dependent projects using Netbeans.

Eclipse debug-time classpath problem: How do you include a dependent project's output into a web project's runtime classpath?

So I started with a web services project (just a dynamic web project) that builds and debugs correctly from eclipse. We've pulled a chunk of common code out that we want to put into a shared library so now those classes are going into a separate jar project that the web project references.
On the web project, I did Project->Properties->Java Build Path->Projects->Add and added the jar project. And this correctly solved all the compile-time classpath problems and everything builds fine. But at runtime, when the tomcat server fires up, spring attempts to inject some of the classes contained in the jar file and I get a NoClassDefFoundError.
My .class and properties files and the contents of my META-INF directory are showing up in the ./build directory, but my WEB-INF/lib directory seems to be referenced in-place, and the jar dependency doesn't get copied in to it to show up as part of the Web App Library.
What is the magical incantation to tell eclipse that the other jar project needs to be available to tomcat at runtime? From our ant build script, we first just build the other project into WEB-INF/lib and everything works fine, but not for eclipse debugging.
I figured this out after spending some time on it. If you are in Eclipse Helios , go to properties > deployment assembly > add > project and select the dependent project you wish to add.
Java EE module dependencies would solve this problem.
You have already done the task of extracting your common classes into its own project, possibly because other projects depend on these classes. Either way, you'll have to ensure that this is a Utility project (appears under Java EE in the project wizards), and not just a plain Java project.
One that is done, you can proceed to add the Utility project to your build path (compile-time path) as you have figured out.
The additional (final) step is to establish a Java EE module dependency between your Dynamic Web project and the shared library, which causes the utility's classes to be placed in WEB-INF\lib during deployment, and even during export of the WAR. To do so, visit the dynamic web project's properties, and browse to the Java EE module dependencies. Ensure that your utility project is selected here. Redeploy/publish your application and you should be good to go.

Categories

Resources