i know, similar questions have been asked here, none of them seemed fit exact problem. have following (partial) directory structure:
src |__view |__tweetview.java |__tweetview.html
in tweetview.java, i'm trying resource url of tweetview.html follows:
string htmldocname = "tweetview.html"; class thisclass = this.getclass(); url htmlresourceurl = thisclass.getresource(htmldocname);
this works fine in eclipse (neon.2), in intellij (2017.2.3), htmlresourceurl
null
. i'm aware location of html file might not ideal (should go in resources folder), various reasons, not supposed change right now.
i observed src-folder marked "sources" folder in project structure in intellij, , sub-folders aren't explicitly marked. project settings aren't shared across eclipse , intellij, since project uses maven. note: problem stated regard running project java application directly within respective ides, not jar/war export.
i saw intellij has these "resource patterns" define file types should considered resources, couldn't work adding .html, neither nor without wildcards (and according intellij website, .html considered resource default anyway).
does have idea problem might be? since works in eclipse, ideally solve problem through configuration in intellij, rather changing code.
edit: here's pom:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>demo</groupid> <artifactid>demo</artifactid> <version>0.0.1-snapshot</version> <build> <sourcedirectory>src</sourcedirectory> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> <resources> <resource> <directory>src/view</directory> </resource> </resources> </build> <dependencies> <dependency> <groupid>com.twitter</groupid> <artifactid>hbc-twitter4j</artifactid> <version>2.2.0</version> </dependency> <dependency> <groupid>org.eclipse.jetty</groupid> <artifactid>jetty-server</artifactid> <version>9.4.0.m1</version> </dependency> </dependencies>
in eclipse, if "run java application", don't think executes maven. intellij, on other hand detect have maven project , run necessary tasks application running.
at least, that's experience using both
there's target/classes/tweetview.html , target/classes/view/tweetview.java
you set src
directory sources (java files) resources src/view
folder.
so, java classes in view folder staying in view folder. files (except java) in view folder moved root classpath, therefore class loader doesn't know given class
my suggestion move java files mavens preferred location of src/main/java
, can leave html files
Comments
Post a Comment