I have created an eclipse plugin and I wanted to deploy during eclipse runtime. I have below package structure.
com.myplugin
|
---resources
|
---server.bat
As part of the plugin job, "server.bat" file should be executed.
I packaged the plugin as .jar file including resouces folder in the binary and placed in to the eclipse "plugins" folder.
Plugin took effect and it does work fine, but I have a problem while executing the "server.bat" file, which is inside the jar that I generated. The error message says:
"Windows cannot find "resources\server.bat" make sure you typed name
correctly and try again"
I tried with relative paths and absolute paths, but it didnt work.
Here is the code doing that work:
URL url = Activator.getDefault().getBundle().getEntry("/resources/server.bat");
String fileURL = FileLocator.toFileURL(url).toString();
String commandLine = "cmd.exe /c start " +fileURL;
Process process= Runtime.getRuntime().exec(commandLine);
I got the "fileURL" output:
file:/D:/Program
Files/IBM/SDP/configuration/org.eclipse.osgi/bundles/2392/1/.cp/resources/server.bat
I am not sure this is correct.
Hope this is clear enough to answer the question.
Alternatively, please suggest some other way, such as creating features to deploy the plugin with folder structure. I haven't tried this option yet.
I have had a similar problem when I export my plugin. I had to refer an exe file stored in my plugin jar file. When the plugin was exported I can not access the zipped file, while it is accessible when I develop the plugin cause eclipse looks for the file in my "development folder".
To solve the problem I created a plugin feature and in the "Included Plug-ins" tab of feature.xml I checked the option
Unpack the plug-in archive after the installation.
for the plugin which contains the exe file.
Using this option you will find your plugin files in a folder under the eclipse plugin folder and you will be able to access them as regular files.
For example
Bundle bundle = <get a bundle of your plugin>;
URL url = FileLocator.find(bundle, new Path(<relative path from plugin root to your file>), null);
try {
url = FileLocator.resolve(url);
} catch (IOException e) {
e.printStackTrace();
return false;
}
Otherwise I think you should decompress your jar.
Hope this help.
EDIT
As I said you can create a feature project(for an example look here) and when you add your plugins, check the option "Unpack the plug-in archive after the installation." Eclipse will do the work for you and you will find your plugin unzipped in the eclipse plugin folder. This solved the problem for me.
Your code seems ok. Note that:
You need to convert your fileURL to file path (i.e. remove "file:/" prefix). This is hugely platform-dependent - try to rely on org.eclipse.core.runtime.IPath and java.io.Path (I don't remember proper code, sorry)
You need to escape the path as it contains space character.
I made it worked using ProcessBuilder. Below is the code snippet..
URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry("resources/server.bat");
String fileURL = FileLocator.toFileURL(url).toString();
ProcessBuilder pb = new ProcessBuilder("cmd.exe","/c",fileURL);
pb.redirectErrorStream(true);
Process p = pb.start();
p.destroy();
Ofcourse, i extracted the jar and put that directory to plugins folder of eclipse.
Use the second solution of http://www.vogella.com/blog/2010/07/06/reading-resources-from-plugin/
And don't forget to export the files you want to access in the build configuration of your plugin.
I found this worked well with Eclipse RCP 4, This code took the given gif image from a jar file that was in the given plugin
public ImageDescriptor getImgDesc(final String bundleId, final String fullPath)
throws IOException {
final URL url = new URL("platform:/plugin/" + bundleId + "/" + fullPath);
final ImageDescriptor imgDesc = ImageDescriptor.createFromURL(url);
return imgDesc;
}
....
final ImageDescriptor imgDesc = getImgDesc("com.awe.test","images/Applet24.gif");
final Image applet24 = imgDesc.createImage();
Related
I started working with files, a simple operation of writing and reading files.
But i had an error when writing a file and now i have to fix it by hand.
Thats the problem, i don't know where is my file.
Also i would like to see the file i'm writing.
I am working with intellij idea 2016 1.4, maybe the file is complied in a jar?
Yes, i know that clearing cache its an option.
nothing here: https://github.com/libgdx/libgdx/wiki/File-handling
on the wiki link only talk about where you can find the ablolute path file but thats not my case. I get the file this way:
this.resolver = Gdx.files.local(path + "item"+ String.valueOf(weaponNumber) + ".txt");
String description = this.resolver.readString();
So.. where is the file? thanks
In the desktop version it saves the file in the assets folder inside your android module.
FileHandle file = Gdx.files.local("myfile.txt");
file.writeString("Test libGDX", false);
System.out.println(Gdx.files.getLocalStoragePath());
Output: D:\Dropbox\Projetos\Outros\gdxTest\android\assets\
The project folder in my computer is gdxTest.
In your case you have the path var so probably will be a folder inside assets folder.
But when you pack the desktop game into a jar file, the file will be created in the same folder where your game jar file is located. Usually yourProject\desktop\build\libs.
The difference is because when we configure the desktop project we set the Working Directory in the yourProject\android\assets\ folder. So to Android Studio it is the local folder of your project.
I am currently writing some integration tests with Arquillian. Now I'm stuck at a strange problem:
I have a .war archive and want to add a .jar library to it. I do this with myWar.addAsLibrary(myJar). However, like this the myJar is then located at
myWar
\_ WEB-INF/lib/WEB-INF/lib/myJar.jar
instead of
myWar
\_ WEB-INF/lib/myJar.jar
I made a workaround that exports the jar to the file system and adds it like this:
myWar.addAsLibrary(new File("/home/metalhamster/myJar.jar"),
new BasicPath("/WEB-INF/lib/myJar.jar"));
Has anyone an idea what the problem is? Is it maybe a bug of ShrinkWrap?
EDIT:
What I have tried:
// load original war
WebArchive myWar = ShrinkWrap.createFromZipFile(WebArchive.class, new File("../wgmdb-web/build/wgmdb-web.war"));
// extract jar from war
JavaArchive myJar = myWar.getAsType(JavaArchive.class, new BasicPath("/WEB-INF/lib/wgmdb-business.jar"));
/*
* modify the jar
*/
// replace the jar with the modified version
myWar.delete(new BasicPath("/WEB-INF/lib/wgmdb-business.jar"));
myWar.addAsLibrary(myJar);
Workaround:
// export jar to file system
new ZipExporterImpl(myJar).exportTo(new File("/home/metalhamster/wgmdb/wgmdb-business.jar");
// load it again and add it to the war
war.addAsLibrary(new File("/home/metalhamster/wgmdb/wgmdb-business.jar"),
new BasicPath("/WEB-INF/lib/wgmdb-business.jar"));
Cheers
metalhamster
Actually ShrinkWrap is doing what you are asking: add /WEB-INF/lib/myJar.jar to the lib directory.
To fix this remove the /WEB-INF/lib/:
myWar.addAsLibrary(new File("/home/metalhamster/myJar.jar"),
new BasicPath("myJar.jar"));
The following line of Dart code shows true for existing files when run from the Terminal but false when run from IntelliJ or WebStorm. Can someone explain why and how to set up Idea editors so that it will return the same results as the Terminal run.
bool pathExists(String path) => new File(path).existsSync();
Update
After tinkering I've now found out that if I create the project in WebStorm 5 using 'open directory' it works fine for all(WebStorm, IntelliJ, and the Terminal). The problem is when I try to create the project in IntelliJ 12 as there seems to be no equivalent to open directory it seems to try to create a Java project. WebStorm seems to have better support for creating a Dart application from scratch at the moment. See answers below for instructions.
You really should show the whole program and how you run it, otherwise I can only guess. And my guess would be that you are passing a relative path to the function and you run the program from a different directory than IntelliJ.
Let's say I have this Dart program:
import 'dart:io';
bool pathExists(String path) => new File(path).existsSync();
main() {
print(pathExists('books.txt'));
}
This program will print true when the books.txt file exists in the current directory. I happen to have such file in my home directory, so when I do
ladicek#argondie:~$ dart check_file.dart
it will obviously print true. But if I run the same program from another directory, it will surely print false. And that's probably what happens in your case.
You should check the Run/Debug Configuration in IntelliJ, it lets you configure the directory where the program is started.
Following #CrazyCoder's comment: Selecting
Create New Project
then
Static Web/Web Module
and choose your folder at
Project Location
then expand
More Settings
and finally make sure that
Module File Location
is set to where your main() dart file is located. By default it is set to the content root.
Has the same effect as Open Directory. I've tried it and it works fine.
Hopefully should be a simple question...
I have an integration test module which contains the default directory structure:
src
|-main
|-test
|-java
|-resources
Then within my resources directory I have an xxxx.xml and xxxx.xsd file, and I need to load these files in as part of my test:
#Test
public void should_do_some_stuff_with_xml_and_xsd() // not actual test name
{
File xmlFile = new File("xxxx.xml");
File xsdFile = new File("xxxx.xsd");
...
}
It keeps failing trying to load the file, now I presumed it was down to me needing to give it a relative path from the project root or something. I need this test to run externally to my IDE so I can run the tests on the build server when it gets there...
So my question is, how do I target these files?
The classpath mechanism does not work for files. Relative file paths are resolved from the current directory, not from the classpath elements.
So you could just do
File xmlFile = new File("target/test-classes/xxxx.xml");
File xsdFile = new File("target/test-classes/xxxx.xsd");
However, a much cleaner solution would be to work with InputStreams instead of files. Almost every library that supports File parameters also supports InputStream parameters. And that way you can use ClassLoader magic without manually specifying any paths:
ClassLoader cldr = Thread.currentThread().getContextClassLoader();
InputStream xmlStream = cldr.getResourceAsStream("xxxx.xml");
InputStream xsdStream = cldr.getResourceAsStream("xxxx.xsd");
Reference:
Byte Streams (Sun Java Tutorial)
ClassLoader (javadoc)
InputStream (javadoc)
I am very new to Bamboo. I have got a html file generated using log4j. I wish to put it in user-defined artifacts but don't know how.
It is in surefire-reports folder so I tried giving Source directory as "**/target/surefire-reports/" and Artifact Copy Pattern as "**/*.html" but it doesn't seems to work.
Any idea how to configure it?
Try to change copy pattern to
*.html
and verify your complete path.
I wanted to get all surefire reports from each module, so I created a new Artifact definition with:
Name = Surefire Reports
Location =
Copy Pattern = /target/surefire-reports/.*
This was using Bamboo 3.2.2.
The Location field does not provide the Ant file copy pattern feature, only a fixed path is accepted relative to the working directory.
Set the Location as target/surefire-reports
and the Copy pattern as **/*.html
Also make sure that the Shared checkbox is set, otherwise other jobs will not be able to download the artifact.