Maven Integration for Eclipse

Update Source Folders excludes properties file from classpath

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Not A Bug
  • Affects Version/s: 0.0.12
  • Fix Version/s: 0.9.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Eclipse 3.3.1.1
  • Number of attachments :
    1

Description

When updating java project with maven => update source folders, it sets all necessary src folders to classpath, including the resources folder but sets also an exlude ** on resources. The outcome is that all properties are not the target/classes folder and I am unable to use it. I have to delete manually the exclude directive.

This should be fixed

Activity

Hide
Michael Osipov added a comment -

see the picure. You see that resources subfolders are excluded

Show
Michael Osipov added a comment - see the picure. You see that resources subfolders are excluded
Hide
Eugene Kuleshov added a comment -

Michael, can you please define "unable to use it"? If you look at the source folders for resources, they all should have target build path to set on themselves, so there is no need to copy those files into the target/classes folder. Basically this is intentional and it also prevents JDT to compile .java files that could be found inside resource folders configured as source folders.

Show
Eugene Kuleshov added a comment - Michael, can you please define "unable to use it"? If you look at the source folders for resources, they all should have target build path to set on themselves, so there is no need to copy those files into the target/classes folder. Basically this is intentional and it also prevents JDT to compile .java files that could be found inside resource folders configured as source folders.
Hide
Michael Osipov added a comment -

Eugene,

unable to use means that is excludes everything in the resources folder be to exported into target/classes. Properties files are not available then.
If you want to prevent java files the put an */.java exclude on it.

If you compare the exclude rules m2eclise creates and maven eclipse plugin, you see that mep does exactly that. Excluding only */.java

Show
Michael Osipov added a comment - Eugene, unable to use means that is excludes everything in the resources folder be to exported into target/classes. Properties files are not available then. If you want to prevent java files the put an */.java exclude on it. If you compare the exclude rules m2eclise creates and maven eclipse plugin, you see that mep does exactly that. Excluding only */.java
Hide
Eugene Kuleshov added a comment -

Michael, like I said, that was intentional and I still don't understand what does "properties are not available" mean. Is there particular issue when compiling anything or running/debugging application or tests in Eclipse?

Show
Eugene Kuleshov added a comment - Michael, like I said, that was intentional and I still don't understand what does "properties are not available" mean. Is there particular issue when compiling anything or running/debugging application or tests in Eclipse?
Hide
Brian Fox added a comment -

Eu: I believe the implication is that only properties in the root folder are processed. Sometimes you need to have properties files in a particular java package (ie subfolder under resources) and this isn't handled by m2eclipse right now.

Show
Brian Fox added a comment - Eu: I believe the implication is that only properties in the root folder are processed. Sometimes you need to have properties files in a particular java package (ie subfolder under resources) and this isn't handled by m2eclipse right now.
Hide
Eugene Kuleshov added a comment -

Brian, please don't mix issue about classpath configuration and processing properties. The latter never been supported and I think there is already JIRA issue for that. Anyways, let's not guess and allow Michael explain what problem he having.

Show
Eugene Kuleshov added a comment - Brian, please don't mix issue about classpath configuration and processing properties. The latter never been supported and I think there is already JIRA issue for that. Anyways, let's not guess and allow Michael explain what problem he having.
Hide
Brian Fox added a comment -

We chatted about it on IRC, which is why I understood what he was trying to do: http://irc.rectang.com/logs/codehaus/%23maven/20080105.html

The processing of the property file isn't the problem, it's that it is excluded from the classpath.

Show
Brian Fox added a comment - We chatted about it on IRC, which is why I understood what he was trying to do: http://irc.rectang.com/logs/codehaus/%23maven/20080105.html The processing of the property file isn't the problem, it's that it is excluded from the classpath.
Hide
Eugene Kuleshov added a comment -

Brian, the resources are excluded from JDT build path (so JDT won't do anything about these files), but resource folder is still there. As far as I know that does not affect compilation by any means and if you look at runtime classpath, resource folder is in fact included, which gives us correct results for both compile and run time.

So I don't see why anyone would care if resources are included or not. That is why I asked what exactly does not work in such setup.

Show
Eugene Kuleshov added a comment - Brian, the resources are excluded from JDT build path (so JDT won't do anything about these files), but resource folder is still there. As far as I know that does not affect compilation by any means and if you look at runtime classpath, resource folder is in fact included, which gives us correct results for both compile and run time. So I don't see why anyone would care if resources are included or not. That is why I asked what exactly does not work in such setup.
Hide
Michael Osipov added a comment - - edited

Brian,

thx for helping. Seems like Eugene doesn't really unterstand the issue.

Eugene,

you name it. All resources are excluded from JDT build path. The result is, that any file in the resources folder won't be copied to the classes folder. There resources are not accesible at runtime with ClassLoader.getResourceAsStream() if you lauch it with eclipse.

In contrast to that the maven eclipse plugin sets the default exclude on tht resources to '*/.java'. m2eclipse does ''''.

Show
Michael Osipov added a comment - - edited Brian, thx for helping. Seems like Eugene doesn't really unterstand the issue. Eugene, you name it. All resources are excluded from JDT build path. The result is, that any file in the resources folder won't be copied to the classes folder. There resources are not accesible at runtime with ClassLoader.getResourceAsStream() if you lauch it with eclipse. In contrast to that the maven eclipse plugin sets the default exclude on tht resources to '*/.java'. m2eclipse does ''''.
Hide
Eugene Kuleshov added a comment -

Michael, when you'll be writing it up, please focus on what functionality don't work (i.e. your tests are failing or application can't be launched from Eclipse) and not how plugin should configure build path. In other words, concentrate on the use cases and not the implementation.

It would be also great if you could attach the test project too.

Thanks.

Show
Eugene Kuleshov added a comment - Michael, when you'll be writing it up, please focus on what functionality don't work (i.e. your tests are failing or application can't be launched from Eclipse) and not how plugin should configure build path. In other words, concentrate on the use cases and not the implementation. It would be also great if you could attach the test project too. Thanks.
Hide
Eugene Kuleshov added a comment -

Michael, please look at the actual runtime classpath (i.e. ih Eclipse Debug view). Even if individual files are excluded, the resource folder is still included into the runtime classpath. So, the only weirdness is that Eclipse don't show the package structure for resource folders, but that don't affect runtime classpath, unless there is something else and that is why I am asking you for the test project that would allow reproduce that issue.

I wrote a lengthy blog entry about issues and the rationale for the current implementation you can read it here. http://www.jroller.com/eu/entry/maven_resource_filtering

Show
Eugene Kuleshov added a comment - Michael, please look at the actual runtime classpath (i.e. ih Eclipse Debug view). Even if individual files are excluded, the resource folder is still included into the runtime classpath. So, the only weirdness is that Eclipse don't show the package structure for resource folders, but that don't affect runtime classpath, unless there is something else and that is why I am asking you for the test project that would allow reproduce that issue. I wrote a lengthy blog entry about issues and the rationale for the current implementation you can read it here. http://www.jroller.com/eu/entry/maven_resource_filtering
Hide
Michael Osipov added a comment -

Eugene,

it seems like we have a Problem here. Either you perfectly understand the problem or you just don't want to understand.
What does not work is this:
<pre>
public static void main(String[] args) throws IOException { Properties pros = new Properties(); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/fredck/fckeditor/default.properties"); //InputStream is = Properties.class.getClassLoader().getResourceAsStream("/com/fredck/fckeditor/default.properties"); ResourceBundle bundle = ResourceBundle.getBundle("com.fredck.fckeditor.default"); pros.load(is); System.out.println(pros.getProperty("fckeditor.dir")); System.out.println(bundle.getString("fckeditor.dir")); }
</pre>

it fails with:
<pre>
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:418)
at java.util.Properties.load0(Properties.java:337)
at java.util.Properties.load(Properties.java:325)
at com.fredck.fckeditor.tool.TEstScl.main(TEstScl.java:17)
</pre>

starting with Eclipse just because all resources are set to exclude '*'. If you run initially mvn eclipe:eclipse it sets the exclude perfectly correct to '/.java' so JDT is able to export all resources to target/classes to run with.

Show
Michael Osipov added a comment - Eugene, it seems like we have a Problem here. Either you perfectly understand the problem or you just don't want to understand. What does not work is this: <pre> public static void main(String[] args) throws IOException { Properties pros = new Properties(); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/fredck/fckeditor/default.properties"); //InputStream is = Properties.class.getClassLoader().getResourceAsStream("/com/fredck/fckeditor/default.properties"); ResourceBundle bundle = ResourceBundle.getBundle("com.fredck.fckeditor.default"); pros.load(is); System.out.println(pros.getProperty("fckeditor.dir")); System.out.println(bundle.getString("fckeditor.dir")); } </pre> it fails with: <pre> Exception in thread "main" java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Properties.java:418) at java.util.Properties.load0(Properties.java:337) at java.util.Properties.load(Properties.java:325) at com.fredck.fckeditor.tool.TEstScl.main(TEstScl.java:17) </pre> starting with Eclipse just because all resources are set to exclude '*'. If you run initially mvn eclipe:eclipse it sets the exclude perfectly correct to '/.java' so JDT is able to export all resources to target/classes to run with.
Hide
Eugene Kuleshov added a comment -

Michael, I assume you did read my blog post about resource handling in m2eclipse. Now, can you please open Debug view and copy the actual command Eclipse used to run your test application. The post it here together with the content of .classpath for that project. Thanks.

Show
Eugene Kuleshov added a comment - Michael, I assume you did read my blog post about resource handling in m2eclipse. Now, can you please open Debug view and copy the actual command Eclipse used to run your test application. The post it here together with the content of .classpath for that project. Thanks.
Hide
Cameron Braid added a comment -

I have a similar issue.

I just upgraded from "Maven Integration for Eclipse 0.9.3.20080421-2352" to "0.9.4.20080603-0114"

Under both versions, my .classpath file has this for the resources :

<classpathentry excluding="**" kind="src" output="src/main/resources" path="src/main/resources"/>
<classpathentry excluding="**" kind="src" output="src/test/resources" path="src/test/resources"/>

Using 0.9.3, when launching via the "Java Application" launcher, my project launches fine, however in 0.9.4, my application is unable to load resources from the classpath (files under the src/main/resources/ folder)

for example :
Caused by: java.io.FileNotFoundException: class path resource [hibernate.cfg.xml] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:162)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:603)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
... 66 more

I even tried resetting the launch target's classpath to default entries.

I can resolve this issue by removing th excluded="**" attribute in .classpath, and I originaly thought this was a bug until I noticed that 0.9.3 uses this too.

SO, I must be doing something wrong - however I havn't changed anything in my project, I've just upgraded the plugin.

Regards

Cameron

Show
Cameron Braid added a comment - I have a similar issue. I just upgraded from "Maven Integration for Eclipse 0.9.3.20080421-2352" to "0.9.4.20080603-0114" Under both versions, my .classpath file has this for the resources : <classpathentry excluding="**" kind="src" output="src/main/resources" path="src/main/resources"/> <classpathentry excluding="**" kind="src" output="src/test/resources" path="src/test/resources"/> Using 0.9.3, when launching via the "Java Application" launcher, my project launches fine, however in 0.9.4, my application is unable to load resources from the classpath (files under the src/main/resources/ folder) for example : Caused by: java.io.FileNotFoundException: class path resource [hibernate.cfg.xml] cannot be resolved to URL because it does not exist at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:162) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:603) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333) ... 66 more I even tried resetting the launch target's classpath to default entries. I can resolve this issue by removing th excluded="**" attribute in .classpath, and I originaly thought this was a bug until I noticed that 0.9.3 uses this too. SO, I must be doing something wrong - however I havn't changed anything in my project, I've just upgraded the plugin. Regards Cameron
Hide
Cameron Braid added a comment -

Believe it or not, there is a simple solution.

I just tried a "Project > Clean" and now my app launches just fine.

Oh well - at least my issue is documented here so that someone else may discover it if they run into the same issue.

Regards

Cameron

Show
Cameron Braid added a comment - Believe it or not, there is a simple solution. I just tried a "Project > Clean" and now my app launches just fine. Oh well - at least my issue is documented here so that someone else may discover it if they run into the same issue. Regards Cameron

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: