Eclipse relative ClassPath question - eclipse

New Eclipse user here with a quick question:
I tried changing the following line in my workspace .classpath file to solve a build error that cannot find a referenced project.
<classpathentry combineaccessrules="false" kind="src" path="/EventNotifier"/>
to
<classpathentry combineaccessrules="false" kind="src" path="../EventNotifier"/>
After doing this, I get the following error:
Illegal entry in '.classpath' of project 'occ600server' file: Path for IClasspathEntry must be absolute
Referenced folder in not in same directory as .classpath file but one level up. How do I fix this?
TIA.

You can use a classpath variable for this purpose.
Go to the workspace preferences, Java > Build Path > Classpath Variables
Create a new variable named WORKSPACE_ROOT (or whatever)
Use a <classpathentry ... /> of type var and put your variable at the start of the path attribute without any fancy ${} business.
Like so:
<classpathentry kind="var" path="WORKSPACE_ROOT/project/lib/somelibrary.jar" />
This technique is used by mvn eclipse:eclipse among other things.

Related

Glassfish 4, Eclipse IDE 2019-03 - CustomRealm: AppservPasswordLoginModule cannot be resolved to a type

I would like to implement a Custom Realm by overriding the security classes but I'm getting an error:
AppservPasswordLoginModule cannot be resolved to a type
The import com.sun.appserv cannot be resolved
I followed the steps from this tutorial: https://computingat40s.wordpress.com/how-to-create-a-custom-realm-in-glassfish-3-1-2-2/
What I did:
I created a new java project
Added a new lib folder to my project.
Copied the security.jar(also tried with security-ee.jar) from $glassfish-installation-folder\glassfish\modules to lib folder
I added this line to my .classpath file:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/security.jar" />
<classpathentry kind="output" path="bin"/>
</classpath>
I also tried to add the jar to build path using Eclipse GUI
NOTES: I'm not using MAVEN, I also tried to clean the project as it was mentioned in other answers
After making this steps Eclipse throws me an arror when I want to extend MyCustomModule with AppservPasswordLoginModule:
enter image description here
UPDATE!
I found the JAR that must be added to JAVA build path: glassfish-ee-api.jar
I solved the problem by creating a new library where I copied all the JARS from $glassfish-installation-folder\glassfish\modules
Photo

Why does Gradle->Refresh remove my protobuf source folder from .classpath?

I have an Eclipse/Gradle project that looks like the following. One directory for .proto descriptors and one directory for the generated .java files for inclusion in other projects.
src/main/java
src/main/proto
I want to add my src/main/proto directory as an Eclipse source folder to make editing easier.
So naturally I add <classpathentry kind="src" path="src/main/proto"/> to my .classpath file. The source folder is added and everything is great until I run Gradle->Refresh which unkindly removes the source folder. My guess is that Gradle doesn't find any .java files in the proto folder and therefore removes the entire folder from .classpath. Is there any way to prevent this?
I have also tried:
<classpathentry kind="src" path="src/main/proto">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
from this question without success.
so the thing is that gradle will (re)-generate the .classpath file from scratch if you do the refresh. So anything you haven't defined at the gradle level will be lost!
How do you define the src folders in Gradle ?
Try to put the following block into you build.gradle:
sourceSets {
main {
java {
srcDirs 'src/main/proto'
}
}
}
This should add 'src/main/proto' to the eclipse classpath as long as the folder contain at least one file!

Project is Missing Required Source Folder: "src_ex_common"

I try to open the sample project from google opensource as provided in the following link:
https://android.googlesource.com/platform/packages/apps/Calendar.git
I have imported the 5 git repositories as required in the program but there is still a red exclamation mark near the project and the "Problems" suggested the project is missing required source folder "src_ex_common". I right click the project name => Properties => Java Build Path => Source, i saw
"MainProjectActivity/src_ex_common (missing)".
I right clicked the project name => new=>source folder and attempt to name a new folder called "src_ex_common" but eclipse said The folder is already a source folder. Then i tried to name a new folder called "src_ex_common" in Windows. The problem above is solved but there are many errors then appear in various java files under src.
I googled that some said this might be due to the problem in ".classpath"
The detail of .classpath is listed below:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src_ex_common"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
Did anyone encounter this problem before? Great if u would share your approach to tackle it. Many thanks!
If you open the mkprojectfile file in the root folder, you will see that the src_ex_common folder is linked to the commons library:
<link>
<name>src_ex_common</name>
<type>2</type>
<location>SRC_ROOT_DIR/frameworks/ex/common/java</location>
</link>
You can import this project from the same ex repository that contains the chips dependency.

Build Spring Roo / Export maven project with Eclipse Export -> Runnable JAR file

I have Maven project created with Spring roo in STS 2.5.1.RELEASE (It is Eclipse 3.6.1 + Spring tools + m2eclipse). I have second simple Java project on build path. Everything is working ok within Eclipse.
Now the problem is to build. I cannot do so with maven, because it also requires that referenced project is maven project. For referenced project I just use Eclipse Export -> Runnable JAR file to export and generate ant file for next build.
Doing so for first project, I get runtime error, even though META-INF/spring/applicationContext.xml is both is .jar and in the folder next to .jar
2011-02-19 13:58:39,135-org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/spring/applicationContext.xml]
2011-02-19 13:58:39,405-org.springframework.core.io.support.PathMatchingResourcePatternResolver - Cannot search for matching files underneath URL [rsrc:com/company/test/] because it does not correspond to a directory in the file system
java.io.FileNotFoundException: URL [rsrc:com/company/test/] cannot be resolved to absolute file path because it does not reside in the file system: rsrc:com/company/test/
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:204)
Referenced project is under heavy development, and I cannot move, refactor it or change its nature.
Maven project with Spring roo is parallel version to be developed.
How to build maven project with included eclipse project?
Example.
Project /RooInheritanceMaven has project /RooInheritanceJava on its (eclipse) build path.
.classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/RooInheritanceJava"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
It is incompatibility between Eclipse Export to Executable JAR and Spring.
To be more exact it is
org.springframework.core.io.support.PathMatchingResourcePatternResolver
Similar provlem was before. see
#SPR-3815 Classloader problem - Spring Projects Issue Tracker
try
jar -tf PersonApp.jar >PersonApp.jar.txt
The solution is to extract .classes and all stuff from jar into folder
jar xf PersonApp.jar
and run as
set CLASSPATH=D:\TEMP\KDF.MSSQL\antlr-2.7.6.jar;D:\TEMP\KDF.MSSQL\aopalliance-1.0.jar; <... all jar dependecies listed>
java com/company/PersonApp
Look at onejar-maven-plugin http://blog.jayway.com/2009/03/22/executable-jar-with-onejar-maven-plugin/
Use the Roo command
perform package
to get your application bundled - so that you can deploy it into your own container.

precedence of persistence.xml in hibernate project

I have an eclipse project with several jars for JPA / Hibernate. One of tham contains a META-INF/persistence.xml and I want to override that by defining my own persistence.xml. So I tried using my persistence.xml in src/persistence.xml also src/META-INF/persistence.xml but everytime it seems jar/META-INF/persistence.xml gets picked up.
I also tried editing .classpath file of eclipse projects and moved up classpathentry path="bin" higher up than the library included but still its not picking up my persistence.xml
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/rules"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="DROOLS/Drools"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/drools"/>
</classpath>
In the tutorial I read:
You will need to override these
defaults if you want to change them,
by adding your own persistence.xml in
your classpath, preceding the default
one in drools-persistence-jpa.jar
So I tried using my persistence.xml in src/persistence.xml also src/META-INF/persistence.xml but every time it seems jar/META-INF/persistence.xml gets picked up.
The persistence.xml should be located under META-INF/persistence.xml so the first attempt won't work. And when I look at your .classpath file, I don't see src as source path so the second attempt won't work either.
Try src/main/java/META-INF/persistence.xml instead.
Actually, your project layout really looks like a Maven layout and with Maven, resources typically go to src/main/resources or src/test/resources. But since you didn't mention what tutorial you're following, I can't confirm if this applies here.
Anyway, my suggestion should work.