Referenced libraries not being deployed by Eclipse - java

I setup a Google App Engine project in Eclipse. I added a root level folder to contain libraries for my project. I added all of these libraries to the build path for my project. The code compiles without any errors. When I run the project, I get startup errors NoClassDef errors. When I add these libraries manually to the war directory's lib folder, these errors disappear.
Why isn't Eclipse deploying the libraries on my build path for me? Do I need to have a build script in place for Eclipse to run? A build script that will copy my libraries to the war dir's lib folder?

For standard Java EE project libraries have to be under {web-app}/WEB-INF/lib folder. GAE requires them to be there too to upload to the engine with your code.
Alternatively you can use Maven to define your dependencies and deploy to GAE
UPDATE: GAE project follows standard Java EE project structure to build and deploy a war file. The convention is that your lib folder is in {web-app}/WEB-INF/lib. Google plugin automatically generates such a structure (example from plugins docs):
MyTestProject
src/
log4j.properties
META-INF/
jdoconfig.xml
com/
mytestproject/
MyTestProjectServlet.java
war/
index.html
WEB-INF/
appengine-web.xml
web.xml
logging.properties
classes/
lib/
...App Engine JARs...
The plugin does allow to change location for your "war" directory, but not the location of your libraries since it should follow the Java EE standard.

You can add the libraries to your war/lib directly, and then right click on the libraries to add them to your build path.
Not sure why it doesn't deploy libs on your build path, but I have been working with Eclipse for years and have always done it the way I described. Then I just deploy through eclipse and don't use a build script.

If the library which was not added to lib folder is being developed in the same workspace, I would suggest to enable the "Utility Module" facet in project properties of the library project. Sometimes Eclipse doesn't copy a jar into WEB-INF/lib folder even if the Deployment Assembly and everything else was configured properly.

Related

java.lang.ClassNotFoundException: javazoom.spi.mpeg.sampled.file.MpegAudioFileReader [duplicate]

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.

J2EE project with using classes from J2SE project [duplicate]

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.

External project dependency in Vaadin

I have a Vaadin project and an external Java project. I would like call code in the external project from Vaadin. I have both project imported in Eclipse and the Vaadin project references the external one in Eclipse Java Build Path. Eclipse reports no error but when I deploy the Vaadin application to Tomcat (using Project > Run As > Run on Server), I get the following error:
HTTP Status 500 - java.lang.NoClassDefFoundError: com/example/MyClass
Note that the Vaadin project is based on Ivy, not Maven.
I've tried searching around for Vaadin external project dependencies with no success. I'll be thankful for any suggestions on how to use the external project's code from Vaadin.
The solution was to add the external projects to the classpath of the Tomcat instance in Eclipse. Select
Run > Run Configurations > Apache Tomcat > (your Tomcat instance) > Classpath
Click Add Projects... and add the required project.
This will work for development. For deployment, the external project must be packaged as a library to a .jar file and copied manually (or using a build script) to WEB-INF/lib directory of the Vaadin project (see this answer on the Vaadin forum).
Another solution which will deploy your dependencies directly in the WEB-INF/lib is to :
- Add your external project to the Project / Java Build Path / Projects
- Add your external project libraries (assumed to be Maven here) to the Project / Java Build Path / Libraries
Click on Add Variable / M2_REPO and click on Extend to select the right library.
This part can be painful if you depend on many libraries.
- Add your external project and java build path entries in the Project / Deployment Assembly panel.
- Restart your Tomcat instance.
Check the content of the WEB-INF/lib directory under:
eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\your_ project\WEB-INF\lib
Take your external project and export it as a jar. Then copy your new jar and any dependencies into the WEB-INF/lib directory of your vaadin project. This will work in a deployment as well as development environment.

eclipse, wtp and tomcat configuration for source folder

I have a java project in eclipse which is having jar file reference of other projects.
Now, I have removed those jar files and added projects in eclipse, no compilation error in eclipse. I have configured Tomcat server in eclipse.
But server doesn't get loaded when i add project instead of jar files.
I have observed following path in eclipse workspace:
<<Eclipse IDE workspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ESW\WEB-INF
under WEB-INF folder, jar files and class files are located. All jar files are loaded to 'jar' but under classes folder no class files are present at this directory. here i am expecting class files of the project which i have added in source folder instead of jar files. how can i do it?
Please try to use the Deployment Assembly option (Project Properties ---> Deployment Assembly ) to configure which files to be deployed to the WTP Tomcat . Before eclipse 3.5 or before , this option is called something likes J2EE Module Dependencies
Deploy path is relative to the your <<Eclipse IDE workspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ESW\ while source path is relative to your project folder.

copy libs into web archieve

I have an eclipse project in which dependent jars are in a separate folder called libs.
Is there a way in eclipse to configure all the jars in lib folder to be copied into webarchieve's lib folder automatically when I export the war file from eclipse or debug it on server?
I am using tomcat 7 as server runtime.
Sure, just go to the
project properties -> Deployment Assembly -> Add -> Archives
Any archive that you add this way to dynamic web project would be copied to WEB-INF/lib folder.

Categories

Resources