Shrinkwrap addAsLibrary() add library to wrong path - jboss-arquillian

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"));

Related

"no main manifest attribute" error in intellij when executing jar

I'm working on a kotlin project that I want to execute as a jar. This is all done in IntelliJ Idea and I went about making the jar using the artifacts.
The process I followed was (as illustrated by an Idea guide):
Add artifact (as jar) from project structure
Build jar
Run jar
After this, I get a
'no main manifest attribute, in ____.jar'
What I have tried after reading several stack overflow questions:
Checking that the manifest file is in the correct folder and has the correct path in the artifact
Adding code to the build.gradle file for the jar->manifest portion
Trying the method of moving the manifest stuff into a resources folder
Checking that the jar exists
Moving the manifest stuff into a different folder (java,kotlin,out folders)
Making sure that the manifest file is in the correct format
All of the above has not worked.
Something that is confusing to me is that, even when I alter the manifest file to be in "incorrect" format, it still gives the same error. The path stated in the artifact's details is correct yet there is no difference even when I purposely input incorrect items in the manifest file. Not sure if that is the"real" problem but I'm also not sure how to fix that as well
None of the solutions worked for me.
I solved it in this way:
When setting up the artifact, change:
Meta-inf: (...)\src\main\ (you must remove "java")
Also, there was a problem with resources, solved this way:
When setting up the artifact:
Output Layout > Add copy of > Directory content > resources.
That's all!
For anyone that may have encountered this problem in intellij and did not find a solution in any other posts, what helped me was
Navigating to Project Structure
Going to the Artifacts tab
Explicitly adding a new META-INF/ directory in my jar
Adding the created MANIFEST.MF file to the META-INF/ in the jar FROM THE ARTIFACTS TAB
Rearranging the order for the META-INF/ to be at the top
Building and running
The end result looked like this
while creating the exeutable jar file explicitly create a mainfest.txt file
that should be in order of the directory structure and mainfest.txt file should contain only one line (Main-Class:name of the class containg main method)then run the jar tool

Adding external Jar to Pentaho Kettle

I am working on Pentaho Kettle version 5.0.1. In one of my transformation I am using javascript component where I am calling a method located in the JAR which I have copied to the lib folder of data-integration and everything is working fine in my local. But in my dev environment(I run it using kitchen) I don't have permission to copy my Jar file to the lib folder due to the restrictions on the server. Is there any other way using which I can supply the path of my custom Jar during run time so that the Kettle Job/Transformation can use it while being executed. Is there a way Kettle can pick the Jar location other than data-integration/lib?. Any help will be appreciated.
Take a look into kitchen.sh (and pan.sh). At some point the script starts adding stuff to the classpath. You can add more folders to the classpath there.
You still need permissions to edit the kitchen.sh file, though. If you can't do that, I suggest creating a copy of kitchen.sh you can write, in a separate location, and change the $BASEDIR folder to the actual PDI installation, so that kitchen can be located elsewhere.
If you have permission you can put your jar in another directory and after you specify this directory in the launcher.properties which you find in data-integration\launcher.
For exemple: if you put your jar in this directory: /export/home.
In launcher.properties: you will add this path and precisely libraries=../test:../lib:../libswt:../export/home

How to refer a file from jar file in eclipse plugin

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();

Maven test/resources directory and integration test

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)

Bamboo artifacts

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.