I'm working on a simple JSP/Servlet/Tomcat webapp for my class. The professor asked us to use a folder structure that is slightly different than the default dynamic web project structure. Rather than using the webcontent folder he wants all of our source code under src/main/java and src/main/webapp.
When I run the app my welcome file displays fine, but when I try to access my servlets I get:
Http 500 SEVERE: Allocate exception for servlet InitDb
java.lang.ClassNotFoundException. I'm pretty sure it's a build path error. I have final/src on the build path but I am receiving the warning
"Cannot nest 'final/src/main/webapp/WEB-INF/classes' inside 'final/src'. To enable the nesting exclude 'main/' from 'final/src'
I have this in my deployment assembly:
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
When I exclude main/ the warning goes away, but it doesn't fix the problem. I would appreciate any advice. Thanks.
I had the same problem even when I created a fresh project.
I was creating the Java project within Eclipse, then mavenize it, then going into java build path properties removing src/ and adding src/main/java and src/test/java. When I run Maven update it used to give nested path error.
Then I finally realized -because I had not seen that entry before- there is a <sourceDirectory>src</sourceDirectory> line in pom file written when I mavenize it. It was resolved after removing it.
I wanted to throw in a non-mavenish answer to this thread.
Due to version control and strict directory structure reasons, I was unable to follow Acheron's answer (the best answer) of doing something similar to removing src/ and adding src/main/java and src/test/java to the build path.
I had actually been off-and-on battling this nested build path issue for a couple weeks. The answer to the problem is hinted in the error message:
To enable the nesting exclude 'main/' from 'final/src'
Fix
In your build path, you need to edit your Inclusion and Exclusion Patterns by clicking on Excluded: (None) and then Edit...:
Go to the navigator and press right click on the project
Build Path
Configure Build Path
Source (tab)
There you can add main/webapp/WEB-INF/classes as an Exclusion Pattern. Then it should allow you to add main/webapp/WEB-INF/classes to the build path as a separate source folder.
Here is a simple solution:
Right click the project >> properties >> build path;
In Source tab, Select all the source folders;
Remove them;
Right click on project, Maven >> Update the project.
Try this:
From the libraries tab:
Eclipse -> right click on project name in sidebar -> configure build path -> Libraries
Remove your web app libraries:
click on "Web App Libraries" -> click "remove"
Add them back in:
click "Add Library" -> click to highlight "Web App Libraries" -> click "next" -> confirm your desired project is the selected option -> click "Finish"
Highlighting "Web App Libraries":
I had the same issue and correct answer above did not work for me. What I did to resolve it was to go to Build Path->Configure Build Path and under the source tab I removed all the sources (which only had one source) and reconfigured them from there. I ended up removing the project from eclipse and import the maven project again in order to clear up the error.
In my case I have a gradle nature project in eclipse, the problem was in a build.gradle, where this sourceSets is specified:
sourceSets {
main {
java {
srcDir 'src'
}
}
}
This seems to works well with intelliJ,however seems than eclipse doesn't like nest src, src/java, src/resources. In eclipse I must change it to:
sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
}
You have to separate your sources and your target directory where the build output goes. It's also important to note that no class files ever can end up in the source directory. This is not against your professor's advice - actually he's promoting the maven standard source structure going for ./src/main/java and ./src/main/webapp. The second one should hold eg. the mandatory WEB-INF/web.xml file but you will never put actual classes there.
What you need to change is your target directory. I suggest going with the same standards and choosing the name "./target" for this. All the built files will go in here and packaging that up will result a correct deployable artifact. Should you migrate to using maven later, it'll also help doing this in a scripted, repeatable way.
Hope that clears up your issue.
The accepted solution didn't work for me but I did some digging on the project settings.
The following solution fixed it for me at least IF you are using a Dynamic Web Project:
Right click on the project then properties. (or alt-enter on the project)
Under Deployment Assembly remove "src".
You should be able to add the src/main/java. It also automatically adds it to Deployment Assembly.
Caveat: If you added a src/test/java note that it also adds it to Deployment Assembly. Generally, you don't need this. You may remove it.
This started taking me down a huge rabbit hole of fixing glitches with Eclipse, however I just deleted the project from Eclipse and reimported it to fix it.
Got similar issue. Did following steps, issue resolved:
Remove project in eclipse.
Delete .Project file and . Settings folder.
Import project as existing maven project again to eclipse.
For Eclipse compiler to work properly you need to remove final/src from the source path and add final/src/main/java instead. This may also solve your problem as now the build directory won't be inside the Java source folder.
It depends on which folder one is telling "Use as Source Folder" to. In the structure on the picture if one says it to the folder "target" or "generated", he gets the "nested" error. But on "cxf" folder, which is the last, mentioned in the pom.xml's 'plugin' section and where from the package structure begins (as shown on .wsdl file), i.e. - the right folder to do it 'source' one, then there is no error
If other solutions did not work and you are using any plugin adding sources in your pom.xml check it. I used build-helper-maven-plugin to add classes generated from openapi specification with incorrect configuration:
<source>${project.build.directory}/generated-sources/openapi/src</source>
instead of correct:
<source>${project.build.directory}/generated-sources/openapi/src/main/java/</source>
So after correcting:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/openapi/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Make two folders: final/src/ to store the source java code, and
final/WebRoot/.
You cannot put the source and the webroot together. I think you may misunderstand your teacher.
Related
from the beginning, while trying to deploy a war under Jetty, I have an error, and in order to understand from where the error is comming, I would like to put a breakpoint in a class (SimpleCDI) located in a dependency (a jar which is downloaded by MAVEN). I work under MAC and when I hit Command + Shift + T and look up "SimpleCDI" class, it points that the class is within org.jboss.weld package
Here is a printscreen of my research
And when I click on the "C SimpleCDI org.jboss.weld" line, it returns an error message
org.eclipse.core.runtime.CoreException: The class file is not on the classpath
at org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor.doSetInput(ClassFileEditor.java:694)
at org.eclipse.ui.texteditor.AbstractTextEditor$5.run(AbstractTextEditor.java:3154)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:437)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:353)
at org.eclipse.ui.internal.WorkbenchWindow$14.run(WorkbenchWindow.java:2195)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2191)
at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3172)
I checked that I have the right dependency (weld-servlet-2.4.5.Final.jar) with
SimpleCDI" in it.
I noticed that the eclipse icon of my dependency "weld-servlet-2.4.5.Final.jar" is the following
It is a jar file without attached source. Actually, I can see this dependency in Eclipse in one of my module "Tourism-Services" (I have a Maven multi module project) in the "Referenced Librairies" folder with the icon mentioned above, but the Maven dependency that import this jar is located in another module "Tourism-Core" which is imported itself in "Tourism-Services" module. I notice in passing that I cannot see "weld-servlet-2.4.5.Final.jar" in "Referenced Librairies" folder of "Tourism-Core" module (why ?)
My main question is : why cannot I edit "SimpleCDI" class and put a breakpoint in order to debug upstream
I've also been using the CodeMix plugin, have you tried to remove the Open Type binding from the CodeMix preferences? Preferences -> Codemix -> Bindings. From there uncheck the "Open Types on COMMAND+SHIFT+T" and do apply and close. This will get you to use the regular Open Java Type from Eclipse.
Cheers
a plugin was causing the error. It is CodeMix plugin
I tried to uninstall it : help->Eclipse Marketplace->Installed
I obtain the following screen
I chose uninstall in the dropDown
But it doesn't work.
I have found a workaround : https://www.genuitec.com/forums/topic/uninstall-codemix/
But it is temporary. I tried to find CodeMix in Eclipse plugin folder (I work under MAC), but there is nothing. Do you see another way ?
When I try to make a project in IntelliJ I receive the following error on this line:
Sentence sent = new Sentence();
sent.emptySegments();
Error:
Error:(151, 10) java: cannot access javax.xml.bind.RootElement
class file for javax.xml.bind.RootElement not found
Sentence is a class which implements the RootElement interface
import javax.xml.bind.RootElement;
...
public class Sentence extends MarshallableRootElement implements RootElement {
All packages exist and I can jump to declaration of each interface or class but I don't know why IntellJ says it cannot access or find them? However RootElement is an interface and not a class
public interface RootElement extends Element {
void validate() throws StructureValidationException;
}
The above declaration is in a jar file named jaxb-rt-1.0-ea.jar and it exists in the Project librarians.
Try this
Go to File
Invalidate Caches/Restart
You can choose only Invalidate and restart
(See Invalidate caches on IntelliJ's manual)
The project contained several modules. While the library was added to the project libraries, some modules lacked it in their dependency part. So I solved the problem using the following steps in IntelliJ
Creating a module library and adding it to the module dependencies:
Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
In the left-hand pane of the dialog, select Modules.
In the pane to the right, select the module of interest.
In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
On the Dependencies tab, click + (on the top right) and select Jars or directories.
In the dialog that opens, select the necessary files and folders. These may
be individual .class and .java files, directories and archives
(.jar and .zip) containing such files as well as directories with
Java native libraries (.dll, .so or .jnilib).
Click OK. If necessary, select the Export option and change the dependency scope.
Click OK in the Project Structure dialog.
File -> Invalidate Caches/ Restart
this worked for my after long hours of effectiveless
Rebuilding project worked for me.
Deleting the .idea folder and then running Invalidate Caches/Restart worked for me.
It also may be because you don't have dependencies in classpath, which used in dependencies.
For example: you use library A, but class you're using from A has superclass from library B. But you didn't add B to classpath.
If it is a single file, you can try deleting the file and undoing it. It seems to reindex that particular file alone, which is much faster than Invalidate Caches/Restart. As a precautionary measure, you can take a backup of the file before deleting, just in case if something goes awry.
Another reason might be different versions of same library with more/less methods. This happened for me with Gradle. Sometimes it compiles fine and sometimes, it doesn't. Just find and remove the unnecessary ones.
My Gradle/IntelliJ "big hammer"
(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.
delete the ".idea" folder (<< intellij specific, or whatever "workspace" folder your IDE uses)
..............
./gradlew --stop
OR
gradle --stop
(now delete the folders)
rm -rf $HOME/.gradle/caches/
rm -rf $HOME/.gradle/build-cache-tmp/
(now resume normal gradlew commands like:)
./gradlew clean build
For me just worked, turn off windows defender / add exclusion project folder / idea process.
Similar problem can happen if a library is imported with maven scope runtime.
In such case it isn't accessible by your classes located under src/main/java.
Only classes in src/test/java can directly use runtime dependencies.
I removed this location "amazonaws" file and clean install later run
/Users/testuser/.m2/repository/com/amazonaws
If you've made it this far because rebuilding or invalidating the cache didn't work work you, I found that deleting the class and adding a new one with the same code worked.
In my case there was an old .iml file in the module causing these problems. So if nothing else worked for you, try looking for one.
⬇ Download the last version of IntelliJ.
▶ Install it.
Worked for me. ✌
So i am using the Plugin Eclipse-PMD (http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/) in a shared version control enviroment.
We have multiple smaller projects in the entire project.
Out of the box it seems that this plugin requires individual configuration for every single project.
The way it works it that it searched for a .pmd file in the project and read information from that.
But it's really inconvenient to do that for 10-20 subprojects.
There is a general setting under Preferences -> PMD. But this doesn't seem to apply globally, even if that global checkbox is checked.
What i basically want: I want to configure the plugin to respect a single ruleSet-file in one place.
There is another problem with configuring it subproject-specific: I cannot configure a relative path for the ruleSetFile in the .pmd-file.
The problem with absolute path is that the file is checked into version control ... so with every commit everyone else would have to readjust.
I found this commit: https://github.com/pmd/pmd/pull/36 but i cannot seem to make it work the way it's roughly described.
So, did anyone achieve what i am looking for?
Edit: Actually i cannot even specify any other file that is not ".ruleset" in the .pmd-file as <ruleSetFile> without specifying an absolute path??
The default value for ruleSetFile is ".ruleset". So i thought, analogous to that, i could create a file in the exact same dir, call it fooRules.xml, and specify it via <ruleSetFile>fooRules.xml</ruleSetFile> but it can only find it if put the entire path to fooRules.xml in there?!
Try eclipse-pmd (available in the Eclipse marketplace or via the update site http://www.acanda.ch/eclipse-pmd/release/latest). With eclipse-pmd you can configure your projects to use a single rule set file for several projects. It also stores its path relative to the workspace. You still have to configure each project individually though (for now, this will change in a future release).
To set up eclipse-pmd in the way you described you have to open the project properties of your first project, select the "PMD" property page and add the rule set. Select the rule set type "Workspace" and pick your rule set file.
For every other project you have to open the project's PMD property page where you'll find the previously selected rule set file which simply needs to be checked to activate.
If you set it up this way there will be a .eclipse-pmd file in each project containing the settings. If you check this into your version control system then no one else in your team has to set up anything (apart from installing eclipse-pmd).
Disclaimer: I wrote eclipse-pmd. Mostly because I had the exact same problems as you with the other plugin.
I've been struggling a long time to get this working with PMD for Eclipse. While Eclipse-PMD has this feature built-in, I had some other issues with it (e.g. I think it is not meant to create reports).
The trick was adding the rules to the project as a link.
Create the rule file, e.g. pmd.xml, in the parent folder of the project. Add the file to the projects to be checked, but add it as a reference. Therefore, drag the file from the explorer to the bundle and select:
In the project properties, in the PMD section, check Enable PMD and Apply and Close the settings.
Now close Eclipse. Edit the file with the name .pmd in the project folder by replacing the content with the following:
<?xml version="1.0" encoding="UTF-8"?>
<pmd>
<useProjectRuleSet>true</useProjectRuleSet>
<ruleSetFile>pmd.xml</ruleSetFile>
<includeDerivedFiles>false</includeDerivedFiles>
<violationsAsErrors>true</violationsAsErrors>
<fullBuildEnabled>true</fullBuildEnabled>
</pmd>
Restart Eclipse and right click the project. Select PMD/Check Code. Now, only the violations defined in pmd.xml should be reported.
Configuring PMD only using the GUI does not seem to work for me.
I am attempting to incorporate admob ads in my app. So far I have added the following code
in the onCreate method of my app's main activity...
adView = new AdView(this,AdSize.BANNER,"my code number");
adView.loadAd(new AdRequest());
The program compiles without error but at run time I get the message java.lang.NoClassDefFoundError: com.google.ads.AdView. I have seen a supposed explanation of the problem and the cure here but I could not see how it was applicable to my project because I do not have either a "lib" or "libs" directory within my project.
According to eclipse's SDK manager, I have the most up to date version of everything that I use.
I had a similar problem, but did not have to add the libs folder; I tried, with no success, then removed them afterwards, when I realized that I had just forgotten to export the included Jar archived.
Fix:
Select project settings > Java Build Path, then Order and export.
Here, check the GoogleAdMobAdsSdk-package.
This should solve the NoClassDefFoundError-issue.
Just create manually the "libs" folder, and add your libraries there. By default, they doesn't exist
Project-> Clean
Project settings -> Java Build Path. Open "Order and export" tab.
Check GoogleAdMobsAdsSDK.
It is worked for me.
Was getting this error updating from android 16 to 20.
Solved by going to Java Build Path, Order and Export tab, checked and moved GoogleAdMobAdsSdk just under my source. For some reason that fixed it.
Changing the order back didn't break it. So some setting must have needed to be initialized.
I had this problem, and this problem too:
Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode and Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode
Despite many hours of following all solutions listed the only way I could get my app to work was to use the AdMob banner example here:
https://github.com/googleads/googleads-mobile-ios-examples/tree/master/admob/SmartBannerExample
And re-build my project around it, copying my files in to that project. If you are stuck, try it.
Don't know why it worked, but now it does. Something in my project was very wrong. Now I can carry on with my work. I love Google/Android, but really what a mess!
See this answer Android update 17 seems incompatible with external Jars.
You need to put all jars in libs folder insted of lib.
It's not enough only to add "GoogleAdMobAdsSdk-6.4.1.jar" in Java Build Path,then you should switch to table:Order and export.check the "GoogleAdMobAdsSdk-6.4.1.jar" here.
UPDATE:
Select project settings > Java Build Path, then Order and export.
Here, check the google-play-services.jar.
This should solve the NoClassDefFoundError-issue.
In my case I needed to click on the "Android Private Libraries" on the "Order and Export" Tab
Go to Properties - Java Build Path - Order and Export and check every Checkmark! That did the trick for my project.
I am trying to exort a Java project with Eclipse 3.6.1 to a runnable Jar. This used to work properly but failed today, afer I added some additional Jars to my class path.
The error is
duplicate entry: some/class.class
Interestingly, there is a duplicate entry for almost any class in my buildpath. Even though I did not change anything. The Jars I added do not contain duplicate classes.
Question: Is this some kind of Eclipse bug? Am I ovrlooking something obvious? Does anybody have an idea what could cause this error?
Cheers
You could try modifying the line
<jar destfile="/Volumes/resi/talosBase.jar" filesetmanifest="mergewithoutmain">
in your build file to be
<jar destfile="/Volumes/resi/talosBase.jar" filesetmanifest="mergewithoutmain" duplicate="preserve">
This will cause ant to preserve the first entry of any duplicate and ignore the rest. The default behavious is "add" so you can end up with multiple files of the same fully qualified name. The other valid entry for this paramter is "fail" but I don't think that will help you here.
OLD-Answer
Delete your last created runnable jar either manually or alter the generated ant script to do so before creating a new one
Cleaning the project should help. It is not eclipse bug, but rather jar maker's one. Apparantly, it takes the classes and see that such classes already exist and can't understand that it should replace them instead of adding.
Cleaning the project will help you.
I too had the same problem, but then I slightly modified the build settings in Eclipse to the one mentioned below.
This solved the duplicate entry issue for me, it just copies all required jars to a subdirectory.
in my case cleaning the project doesnt change any thing so i use a workaround :
genearte a build script by activation by save ANT script ant script genration
execute the ant script manually or in eclipse (its better)
executing script by eclipse
and I change my ant build script by adding option as indicate in this post duplicate="preserve" (to keep the first version on the duplicated file )
hope it help
Try removing the jars and adding it once again.. this got the error resolved for me..