I am trying to get a simple Struts 2.x project to run in Eclipse (using Glassfish 3.1.2.2). I started with a copy of a working project and deleted all the Eclipse generated files (ie. the “.settings” directory, and the “.classpath” and “.project” files). Here’s what my build looks like:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'org.apache.struts:struts2-core:2.3.8'
}
sourceSets {
main {
java {
srcDirs "src"
}
resources {
srcDir "src"
}
}
}
When I go to add the project on the Eclipse server tab, I get a pop up that says: “There are no resources that can be added or removed from the server.”
What am I doing wrong?
Although my Struts app still isn’t running correctly, I was able to solve the above problem that I had. It had to do with the generated .settings/org.eclipse.wst.common.project.facet.core.xml file. When I added the following to my build script, I am able to add the project on the Eclipse server tab.
eclipse {
wtp {
facet {
facet name: 'java', version: '1.7'
facet name: 'jst.web', version: '3.0'
facet name: 'sun.facet', version: '9'
facet name: 'wst.jsdt.web', version: '1.0'
file {
withXml {
def node = it.asNode()
node.appendNode('runtime', [name: 'GlassFish 3.1.2 2'])
node.appendNode('fixed', [facet: 'wst.jsdt.web'])
node.appendNode('fixed', [facet: 'java'])
node.appendNode('fixed', [facet: 'jst.web'])
}
}
}
}
}
Found that the other problem is with the generated org.eclipse.wst.common.component file in the .settings folder. I copied the line from EclipseWtpComponent DSL for adding a wb-resource element, but it doesn’t appear in the component file. Here’s my eclipse block so far:
eclipse {
wtp {
facet {
// you can add some extra wtp facets; mandatory keys: 'name', 'version':
facet name: 'java', version: '1.7'
facet name: 'jst.web', version: '3.0'
facet name: 'sun.facet', version: '9'
facet name: 'wst.jsdt.web', version: '1.0'
file {
//if you want to mess with the resulting XML in whatever way you fancy
withXml {
def node = it.asNode()
node.appendNode('runtime', [name: 'GlassFish 3.1.2 2'])
node.appendNode('fixed', [facet: 'wst.jsdt.web'])
node.appendNode('fixed', [facet: 'java'])
node.appendNode('fixed', [facet: 'jst.web'])
}
}
}
component {
resource sourcePath: 'extra/resource', deployPath: 'deployment/resource'
}
}
}
Okay, so like I was going about this the wrong way. I still needed to added a couple of wb-resource elements to the generated org.eclipse.wst.common.component file, but its not as bad as the last two posts make it sound. Here’s the build script that I used:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'org.apache.struts:struts2-core:2.3.8'
}
eclipse {
wtp {
component {
resource deployPath: '/', sourcePath: '/WebContent'
resource deployPath: '/WEB-INF/classes', sourcePath: '/src'
}
}
}
sourceSets {
main {
java {
srcDirs "src"
}
resources {
srcDir "src"
}
}
}
Note: This requires that a src and WebContent folder exists in the project’s directory.
Next I ran the eclipse task and then imported the project into Eclipse. I then right clicked on the project, selected Project Facets and clicked on the Runtimes tab. I put a check mark on the GlassFish runtime. I also selected the “Default Configuration for GlassFish” from the Configuration drop down box. Click ok and it runs.