How to remove duplicate jars from a gwt-application runtime config file - java

I am currently working towards upgrading our client side GWT setup, which we use when we deploy apps to google app engine. We also use DataNucleus's JDO on google app engine. The project is built using maven.
I have the following error below that occurs during runtime for my GWT app runconfig in legacy dev mode (the mode should not matter):
Plugin (Bundle) "org.datanucleus" is already registered. Ensure you
dont have multiple JAR versions of the same plugin in the classpath.
The URL
".../target/project/WEB-INF/lib/datanucleus-core-3.1.3.jar"
is already registered, and you are trying to register an identical
plugin located at URL
".../.m2/repository/org/datanucleus/datanucleus-core/3.1.3/datanucleus-core-3.1.3.jar."
at org.datanucleus.plugin.NonManagedPluginRegistry.registerBundle(NonManagedPluginRegistry.java:541)
I understand that this is a duplicate jar and I need to remove the duplicate. I am just at a loss for how to do it easily in my gwt app runtime configuration. What happens is that inside the runtime config, it uses the "default classpath". The default classpath includes the following:
Eclipse Project Name
(bunch of things like /src/main/java etc.)
/target/*
Maven Dependencies
There is the problem though. The datanucleus jar exists in the target/project/web-inf/lib folder and maven dependences. The maven build put the dependencies in the target folder, so the build is doing the right thing and the runtime config just has a duplicate pointer so to speak.
When I try to tweak the runtime config file, I do not have the ability to edit the "default classpath" included under the Classpath tab. It is an un-editable bundle in eclipse. The next thing I could do is remove that default classpath bundle, but then I have to manually add each jar to my runtime config by hand, which may take a couple hours.
Is there some sort of way to craft my own classpath that has everything from the default classpath less a folder or two and be picked up in the "Classpath" tab?
Is there a better way?

Related

while loading excel data into database using servlets ( java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook) [duplicate]

How should I add JAR libraries to a WAR project in Eclipse without facing java.lang.ClassNotFoundException or java.lang.NoClassDefFoundError?
The CLASSPATH environment variable does not seem to work. In some cases we add JAR files to the Build Path property of Eclipse project to make the code compile. We sometimes need to put JAR files inside /WEB-INF/lib folder of the Java EE web application to make the code to run on classes inside that JAR.
I do not exactly understand why CLASSPATH does not work and in which cases we should add JARs to Build Path and when exactly those JARs should be placed in /WEB-INF/lib.
The CLASSPATH environment variable is only used by the java.exe command and even then only when the command is invoked without any of the -cp, -classpath, -jar arguments. The CLASSPATH environment variable is ignored by IDEs like Eclipse, Netbeans and IDEA. See also java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable.
The Build Path is only for libraries which are required to get the project's code to compile. Manually placing JAR in /WEB-INF/lib, or setting the Deployment Assembly, or letting an external build system like Maven place the <dependency> as JAR in /WEB-INF/lib of produced WAR during the build, is only for libraries which are required to get the code to deploy and run on the target environment too. Do note that you're not supposed to create subfolders in /WEB-INF/lib. The JARs have to be placed in the root.
Some libraries are already provided by the target JEE server or servletcontainer, such as JSP, Servlet, EL, etc. So you do not need put JARs of those libraries in /WEB-INF/lib. Moreover, it would only cause classloading trouble. It's sufficient to (indirectly) specify them in Build Path only. In Eclipse, you normally do that by setting the Targeted Runtime accordingly. It will automatically end up in Build Path. You do not need to manually add them to Build Path. See also How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
Other libraries, usually 3rd party ones like Apache Commons, JDBC drivers and JEE libraries which are not provided by the target servletcontainer (e.g. Tomcat doesn't support many JEE libraries out the box such as JSF, JSTL, CDI, JPA, EJB, etc), need to end up in /WEB-INF/lib. You can just copy and paste the physical JAR files in there. You do not necessarily need to specify it in Build Path. Only perhaps when you already have it as User Library, but you should then use Deployment assembly setting for this instead. See also ClassNotFoundException when using User Libraries in Eclipse build path.
In case you're using Maven, then you need to make absolutely sure that you mark libraries as <scope>provided</scope> if those are already provided by the target runtime, such as JEE, Servlet, EL, etc in case you deploy to WildFly, TomEE, etc. This way they won't end up in /WEB-INF/lib of produced WAR (and potentially cause conflicts with server-bundled libraries), but they will end up in Eclipse's Build Path (and get the project's code to compile). See also How to properly install and configure JSF libraries via Maven?
Those JARs in the build path are referenced for the build (compile) process only. If you export your Web Application they are not included in the final WAR (give it a try).
If you need the JARs at runtime you must place them in WEB-INF/lib or the server classpath. Placing your JARs in the server classpath does only make sense if several WARs share a common code base and have the need to access shared objects (e.g. a Singleton).
If you are using Maven:
Open the project properties, and under Deployment Assembly click Add...
Then select Java Build Path Entries and select Maven Dependencies
Resolved by setting permissions.
Had related issue using PySpark and Oracle jdbc. The error does not state that the file cannot be accessed, just that the class cannot be loaded.
So if anyone still struggles, check the permissions. Some might find it obvious tho'.
I want to give the answer for the folowing link question ClassNotFoundException oracle.jdbc.driver.OracleDriver only in servlet, using Eclipse
Ans: In Myeclipse go to Server-->left click on Myeclipse Tomcat7-->Configure Server Connector-->(Expand)Myeclipse Tomcat7--> Paths-->Prepend to classpath-->Add jar (add oracle14 jar)-->ok

Is there a way to store the complete configuration of Eclipse so that no further config is necessary?

I mean, I want a developer to be able to check out a project and not have to change anything to in order to get it to build and run. One problem I have run up against is that the proper compiler has to be added to the Build Path -- is there a way this can be done? I realize that the actual JDK will still have to be downloaded but could it be clear from looking at Eclipse which JDK is needed?
The build path is usually stored in a file called .classpath under the project directory, consisting of the classpath entries that were added in Eclipse. Among the entries in the file is one which points to the JRE library.
There is no "complete" configuration that can be saved. Every configuration is stored in a separate file. Some are stored in the project directory. Others are stored in the root directory of your workspace. You'd have to pick exactly which configuration you want to save.
One way to save a configuration for the project and its dependencies is to use a project management tool like Maven. It can configure the required JDK to compile the project (it can even enforce this rule), needed dependencies, etc.
If you set up your project to use an Execution Environment as its JRE Library (as opposed to the "Workspace default" option), then check in the .classpath and .project files, then checkout is a simple process. Execution Environment is an abstraction of the actual JRE/JDK that's installed on any machine/workspace; Eclipse uses that to map to a physical JDK in whatever workspace it's working in.
As others have mentioned, using Maven (or, even better, Gradle) to manage the dependencies will help, too - as long as every developer has the m2e (Maven integration for Eclipse) features installed into his Eclipse.

Deploying GWT app with own external library

I have a GWT project [com.bob.gwt] that uses another library of my own, [com.bob.domain], which is used by both in the client and server. The domain project is exposed via gwt.xml project in com.bob.gwt.
When the server runs, it indicates that some Server classes from com.bob.domain could not be found in the web app, but were found on the class path and added. The WAR directory doesn't have the .java or .class files from com.bob.domain.
The com.bob.domain is added as a library in the Java Bulid Path Window's Projects tab, and also checked on the Order and Export tab in Eclipse. Do I have to set com.bob.domain as a jar and import that jar in com.bob.gwt? Can I just include the domain source in my gwt project so I can debug all at once without having to manually build a jar, and have everything in my WAR folder ready to go for deployment?
During development, it's convenient to use Eclipse's project reference mechanism instead of rebuilding "domain.jar" every time. In that case, it's safe to ignore GWT's warning.
When you perform the "real builds" outside of Eclipse (which I would strongly recommend), you usually can't make use of Eclipse's project reference (except maybe if you're using Ant4Eclipse), so you'll need to tell the GWT compiler (gwtc), and the server side compiler (javac), where to find everything they need, including the domain project's files.
Then, for deployment, you'll need to put "domain.jar" into the "WEB-INF/lib" of your war.

Adding an external JAR to Eclipse Application debug configuration

The issue is as follows:
I have a 3rd party Eclipse plug-in installed and running
The above Eclipse plug-in provides an "extension point" of sorts - a source for a class I can extend/rewrite and replace in the plug-in lib directory (I am not saying it's a great idea, but necessity makes us do things we are not proud of - in-house development has its quirks)
The idea here is to envelop any such change in an external JAR (created by us) so that any change in code wouldn't require us to restart Eclipse to "refresh" the "extension point" class during development.
Eventually, a plugin/bundle will be created and placed as a dependency on the original plugin - so that installing and using that plug-in would actually, you know, work.
Question is - can I somehow add what is basically an external JAR file to Eclipse Application debug/run configuration?
Normally, adding JAR to classpath tab would work for regular Java application debugging/running. Eclipse Application however, doesn't have that tab.
So far the efforts (failed, perhaps due to some stupid syntax error or whatnot) included:
Adding the JAR as a dependency to Bundle-ClassPath: of the plug-in as C:\test.jar
Adding the JAR to the system's CLASSPATH variable
None of that made any difference - the code in the "extension point" that refers to a class in the JAR file fails - exception that boils down to:
Caused by: java.lang.ClassNotFoundException: test.Test
at org.eclipse.osgi.internal.loader.BundleLoader.
findClassInternal(BundleLoader.java:506)
Any pointer/help/criticism would be greatly appreciated.
Update
Apparently putting the JAR in the lib directory of the plug-in and updating the MANIFEST file doesn't work (not that it would help me - since such a solution would require a "refresh", which I am trying to avoid in the first place), so I must be doing something fundamentally wrong.
Does that make any sense or did I miss something in one of those attempts?
I have included an external JAR file to my Eclipse application.....not to the debug/run configurations but to the application itself.
What we did was to wrap the plugin into it's own java project. We are using maven for our build, so the pom.xml lists the dependency as the .jar file (which we put into a lib directory in the project). The manifest.mf file exports the needed classes. My application plugins have a dependency on this project. When I debug/run the application in the workbench I just make sure that this library project is included.
I'm not sure this answers your question completely or not....but I hope it helps.
A first guess based on some assumptions:
You are developing an extension to an 3rd party extension point 'foo'. Your application is a Eclipse Application, that you start via a run configuration. You need to create a new plugin 'foo-extension' which implements the extension point. You have to add the new plugin as a plugin dependency to your application. This way it will be available in the project class path, as well as in the 'Plugin-Ins' tab of your run configuration. Select the new project and when you start your application the extension will be available with the latest change.

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