How to add context file from Wildfly to JHipster - wildfly

The context root file from Wildfly AS looks like this (it must be put in a file name jboss-web.xml as explained here :
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>my-context</context-root>
</jboss-web>
This file and its content have to be copied into the WEB-INF folder of the WAR file.
Of course I can manually add this file after the build and it works.
But is there a way to do it automatically ? Is there in JHipster any folder that copies its content to the WEB-INF folder ?
(Could be great to add such container specific files)

You can put the file in /src/main/webapp/WEB-INF and it will work.
This goes against our goal of an "XML free" configuration, but that's how Wildfly works... BTW I am not sure you can get Spring working on Wildfly, with its broken classloader.

If you are using gradle, after copying yours files into /src/main/webapp/WEB-INF/ you have to add webInf { from 'src/additionalWebInf' } // to add a file-set to the WEB-INF dir. on the file gradle/war.gradle
the file will look like this
apply plugin: "war"
bootWar {
mainClassName = "com.mycompani.JhtestApp"
includes = ["WEB-INF/**", "META-INF/**"]
webInf { from 'src/main/webapp/WEB-INF/' } // this copy all files under this location
//webInf { from 'src/main/webapp/WEB-INF/jboss-web.xml' } //this copy this single file
}
war {
webAppDirName = "build/resources/main/static/"
enabled = true
archiveExtension = "war.original"
includes = ["WEB-INF/**", "META-INF/**"]
webInf { from 'src/main/webapp/WEB-INF/' } // this copy all files under this location
//webInf { from 'src/main/webapp/WEB-INF/jboss-web.xml' } //this copy this single file
}
I hope it is useful for you. for more help visit
https://docs.gradle.org/current/userguide/war_plugin.html

Related

Launch External Tools from Eclipse Plug-in View

I'm building a simple Eclipse plug-in out of preexisting Java application project that relays on 2 external files, one x-executable/application and one .sh script.
The call is implemented in application like this, (which wouldn't work in plug-in):
Process p = new ProcessBuilder("external/application_name", "-d", path).start();
I used External Tool Configuration to define how I want this external files to be launch (when user clicks button on View) and I've exported configuration (example of one):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/softwareevolution/external/application_name}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-d ${project_loc}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${project_loc}"/>
</launchConfiguration>
How can I have this application install along with Eclipse plug in,
or a as a part of it? (see #howlger answer billow) - I set plugin to install as directory /
Connected plugin to Feature project- checked unpack after
installation - and exported Feature project. Select application's
folder on Build/Binary build.
Can I then make use out of this exported .launch files, and if so
under which extension point should I include them in plugin.xml? -
No. (see #greg-449)
The application is supposed to produce 2 files on the path where it
is executed from. I am facing permission denied when trying to
launch it in terminal from plug-in's install directory but not when
launching in workspace. (see #howlger answer billow) - Upon exporting the plugin, initial
permissions of application had changed. Used instructions in p2.inf
to chmod them back.
The newly generated files (from runing .sh script) are missing write permission.
ProcessBuilder
After finally setting up plugin correctly and adding ProcessBuilder I was getting exception message : Cannot run program "rfind_20" (in
directory
"home/adminuser/.p2/pool/plugins/rFindTest3_1.0.0.201809030453/external"
error=2:, No such file or directory
File rfind_20 did exist and permission were 777. The targeted project also existed.
Although the working directory was set to applications folder, the application name was not enough, the absolute path was required as
command argument.
pb = new ProcessBuilder(url.getPath(), "-d", project.getProject().getLocation().toString());
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IProject project= sampleGetSelectedProject();
ProcessBuilder pb;
Process rfind, ajust, copy;
Bundle bundle = FrameworkUtil.getBundle(getClass());//Bundle bundle = Platform.getBundle("rFindTest3");
URL url = FileLocator.find(bundle, new Path("external/rfind_20"), null);
URL dirurl = FileLocator.find(bundle, new Path("external/"), null);
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
try {
MessageDialog.openInformation(
window.getShell(),
"Test",
project.getProject().getLocation().toString());
url = FileLocator.toFileURL(url);
dirurl = FileLocator.toFileURL(dirurl);
pb = new ProcessBuilder(url.getPath(), "-d", project.getProject().getLocation().toString());
//no matter the working directory the absolute path was required!! sending "rfind_20" as command did not work as command
pb.directory(new File(dirurl.getFile()));
rfind = pb.start();
rfind.waitFor();
rfind.destroy();
}catch(Exception e) {
MessageDialog.openInformation(
window.getShell(),
"Test",
e.getMessage());
}
return null;
}
The only remaining mystery is why my sampleGetProject() method wouldn't work in Plug-in Perspective. So just keep in mind to switch to other Perspectives when testing your plug-in.
There are two ways to ship an application as part of a plugin and run it via ProcessBuilder (the *.launch file cannot be used inside a plugin for that):
Extract the executable files from the plugin JAR to a (temp) directory and change their file permissions before running them
Install the plugin as a directory:
In META-INF/MANIFEST.MF add the line Eclipse-BundleShape: dir (see "The Eclipse-BundleShape Header" in Eclipse help - Platform Plug-in Developer Guide - OSGi Bundle Manifest Headers)
Create a Feature Project and connect your plug-in in Included Plug-in, check "Unpack the plug-in archive after the installation"
Create a META-INF/p2.inf file that contains the following (see Eclipse help - Platform Plug-in Developer Guide: "Touchpoint Instruction Advice" in Customizing p2 metadata and "chmod" in Provisioning Actions and Touchpoints):
instructions.install = \
chmod(targetDir:${artifact.location},targetFile:path/to/executable1,permissions:755);\
chmod(targetDir:${artifact.location},targetFile:path/to-executale_which_generates_files/executable2,permissions:733);\
chmod(targetDir:${artifact.location},targetFile:path/to-executale_which_generates_files/,permissions:766);
instructions.install.import = org.eclipse.equinox.p2.touchpoint.eclipse.chmod
If you have a xxx.launch file in the workspace you can launch it using
IFile file = ... get IFile for workspace file
ILaunchConfiguration config = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(file);
DebugUITools.launch(config, ILaunchManager.RUN_MODE, false);
If you have an executable as part of a plug-in then you can't use a .launch file. Instead use FileLocator to get the location of the executable and run it with ProcessBuilder
Bundle bundle = FrameworkUtil.getBundle(getClass());
URL url = FileLocator.find(bundle, new Path("relative path to executable"));
url = FileLocator.toFileURL(url);

How to get resources path from an Eclipse plugin

I am developing an Eclipse plugin using Eclipse Plugin-in-project where it will add a menu item in the toolbar.
My plugin project is depending on one file which is located in the same plugin project I want the path of that file.
Below is the sample code I have used to get the path:
Bundle bundle = Platform.getBundle("com.feat.eclipse.plugin");
URL fileURL = bundle.getEntry("webspy/lib/file.txt");
File file = null;
String path=null;
try {
file = new File(FileLocator.resolve(fileURL).toURI());
path = file.getAbsolutePath();
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
While running from Eclipse Run as > Eclipse Application it is giving me the correct path. But when I export my plugin as jar and add it in my Eclipse plugins folder its not giving me the correct path.
Please help me to resolve this!
Use:
URL url = FileLocator.find(bundle, new Path("webspy/lib/file.txt"), null);
url = FileLocator.toFileURL(url);
File file = URIUtil.toFile(URIUtil.toURI(url));
When your files are packed in a jar FileLocator.toFileURL will copy them to a temporary location so that you can access them using File.
Files in jars have no java.io.File as they are in the JAR file.
You probably want FileLocator.openStream(...) to read the file contents.
If you really want a java.io.File, then you can consider using Eclipse EFS and its IFileStore.toLocalFile(...) to extract the file for you to a temporary directory. Something like EFS.getStore(fileURL).toLocalFile(EFS.CACHE, null) should do what you want, but remember that will put the file in the temp directory and delete it on Eclipse exit.

Creating the default project Jar in gradle through a custom plugin

I'm in the process of building my first custom plugin for gradle. This plugin does a number of things, including configuring the project it's applied to based on other plugins that the project has. One of the things I want this plugin to do is handle all of the Maven publishing work, so that it doesn't need to appear in every build.gradle. Each build does the exact same thing, they just have their source Jar and their base project Jar, and both are (or will be) published to our artifact repository.
That works, I can create the Jar file. However, the Jar file only contains the META-INF folder and manifest file, and none of the classes of the project. Has anyone encountered this problem and know the cause?
// Configure Jar Manifest
jar {
manifest = project.manifest {
from sharedManifest
}
}
// Configure sources Jar manifest
(project.getTasks()).create("sourcesJar", Jar) {
classifier "sources"
from project.sourceSets.main.allSource
manifest = project.manifest {
from sharedManifest
}
}
artifacts {
archives project.tasks.sourcesJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from project.components.java
artifact project.tasks.sourcesJar
pom.withXml {
def root = asNode()
root.appendNode("name", project.name)
root.appendNode("description", project.name + "component of company.")
root.appendNode("inceptionYear", "2010")
}
}
}
repositories {
maven {
//We only publish to the Releases repository if the project is given the property "release"
if(project.hasProperty("release")) {
url "http://clipped/"
} else {
url "http://clipped/"
}
credentials {
if(project.hasProperty("nexusUsername") && project.hasProperty("nexusPassword"))
{
username = nexusUsername
password = nexusPassword
}
}
}
}
}
That was it, Peter, a developer had moved all of the projects calling the plugin from src/main/java to src/java, thinking that the folder structure was unnecessarily deep. Nothing wrong with the plugin code.

Eclipse RCP: add external directories to classpath

I have an eclipse RCP application, where I need to add some external jar files.
The problem is that I can't add the jars simply to a plugin and add this plugin to my RCP application.
For several reasons I must only add paths to directories where the jar files are located. These jar files have to be added to the program's classpath at startup.
And the paths to the directories are a variable (e.g. they are placed in a file).
Is there a possibility to add external paths somehow to the classpath?
add external directory to classpath,there are three method:
> **1. System.setProperty("java.class.path",
> System.getProperty("java.class.path")+";"+"directory");**
File file = new File("/home/../my.jar");
URLClassLoader classloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Method add = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
add.setAccessible(true);
add.invoke(classloader, new Object[] { file.toURI().toURL() });
configurate classpath variable in .bashrc

Eclipse how to reference file in a different src under the same project

My current setup in eclipse is like this:
trunk
--working/src
--resources
I have a java file inside a package under working/src and I am trying to retrieve a file in the resources. The path I am using is "../resources/file.txt". However I am getting an error saying that the file does not exist.
Any help would be appreciated thanks!
Considering your structure
I have package like
trunk
working/src/FileRead.java
resources/name list.txt
Following Code might solve your problem
package working.src;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class FileRead {
public FileRead() {
URL url = getClass().getResource("/resources/name list.txt");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String nameList;
while ((nameList = in.readLine()) != null) {
System.out.println(nameList);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new FileRead();
}
}
Files will be referenced relative to your project path, so use "resources/file.txt" to reference the file.
However, if you want the file to be accessible when you export the program as a JAR, the path "resources/file.txt" must exist relative to your JAR.
It depends on how you have specified your Java Build Path inside eclipse. I have tested two setups with different results:
Define the directory working/src only as build path. You can get the information what is in your build path through: Select project > Properties > Java Build Path > Tab Source. There are all source folders listed. You see there that there is a default output folder defined. All resources that are contained in a build path are copied to the default output folder, and are then available for the eclipse classes there. You can check that in the resource perspective in your bin folder if the resource is copied there. In this setup, only the classes are generated, resources are not copied (and therefore not found).
Define the directory working/src and resources as build path. Then the resource is copied and may then found by the path "file.txt"
So eclipse has a simple build process included and hides that from the developer, but it is a build process nonetheless.