I am developing a chat bot using IBM Watson conversation. When I build the project and run, it gives null in inputStream in the RequestUtils.java class in the java-sdk/conversation. but when I run it from the ide it works.
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties");
I noticed that properties file is not inside the jar. How to add this properties file to the jar when it is being built? What could be the possible cause? Any help is appreciated.
Thanks.
P.S:scehema of the classes are as follows
parent
project1
project2
Maven Dependencies
|-conversation-3.5.3.jar
| |-package1
| |-packeage2
| |-META-INF
|-core-3.5.3.jar
|-package1
|-packeage2
| |-RequestUtils.class
|-META-INF
|-version.properties
I fixed it by my own.
the thread will inherit its context classloader from its parent Thread. If you don't do anything at all in the entire application, all Threads will end up with the system classloader as their context classloader.
So I set the contextClassLoader on my own for the current thread as follows.
ClassLoader classLoader = MyClass.class.getClassLoader();
Thread.currentThread().setContextClassLoader( classLoader );
now it works fine.
Related
I've added a DocumentPreviewControl as per the sample instructions for static report; however when I run our application It's crashed bug when I run the application from a client machine (not developer).
enter image description here
All dll Files are Attched in deployed exe
enter image description here
Problem Solved by using This Method DevExpress-->All Platforme-->DevExpress Assembly Deployment Tool
*Chose Path
*Click Analyze
*Goto Path
*Copy all files and Replace them on Client Machine [installed directory]
(^_^)
In a WPF project I have a block which launch application using:
Process.Start(url);
If it throws an error I would like the application to offer to install the exe the sits on the part of the application folder.
The problem is that I am unable to direct to relative folder in the project in order to launch the application.
Would appreciate any assistance.
Try this. Ensure that your program path is correct at all times.
Process proc = new Process();
proc.StartInfo.FileName = "D:\Program.exe";
proc.StartInfo.WorkingDirectory = Path.GetDirectoryName("D:\Program.exe");
proc.Start();
I am running Cloudbees Jenkins (1.554.2.2) on WebSphere 8.5 with Java 7 on RedHat Linux. I loaded the Artifactory plugin into Jenkins, but when I hit test connection, I receive the following error:
org.apache.commons.logging.LogConfigurationException:
org.apache.commons.logging.LogConfigurationException: Class
org.apache.commons.logging.impl.Jdk14Logger does not implement Log
It appears that the WebSphere JARs are being loaded first which contain a different version of the commons-logging JAR. I am seeing this as well with some other plugins.
I do have the classpath for the Jenkins in WebSphere set to be Parent Last. Also, Jenkins.war directory contains the commons-logging-1.1.3.jar and log4j-1.2.9.jar files.
Has anyone using artifactory plugin on Websphere 8.5 has encountered the issue.
This question has been asked before here
So I followed the tutorial on the H2 Documentation page and used the "Connecting to a Database using JDBC" method of connecting to the database. I First added the h2-*.jar file to the Lib Folder (through Netbeans) and used the following to make the connection to my database I previously created.
Class.forName("org.h2.Driver");
connection = DriverManager.getConnection("jdbc:h2:~/" + DatabaseName);
This turned out to work in the IDE environment, however when I attempted to run the application directly from the jar executable I get the following error:
java.lang.ClassNotFoundException: org.h2.Driver ...
this error occurs at the Class.forName() class loader. So I did a little looking around and found that this was a prominent problem. One solution people use was to extract the class Loader from the current Thread as so:
Thread t = Thread.currentThread();
ClassLoader cl = t.getContextClassLoader();
cl.getClass().getClassLoader();
Class toRun = cl.loadClass("org.h2.Driver");
Unfortunately this seems to still result in the same error, so i'm wondering what i'm doing wrong. Should I be doing something to make sure the Driver is in the class path? I have no I idea how if that's the case.
Thanks!
You need to add the h2-*.jar file to the classpath when running the application, for example using
java -cp h2*.jar -jar yourApp.jar
I have a little GWT/AppEngine Project which uses RPC. Basically I need to get some data from a XML file that resides on the server. But when I use the RPC to read the file in my server-package I am getting a AccessControlException (access denied). Any ideas what the problem is?
//JAXB powered XML Parser
public PoiList readXML() {
try {
unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setEventHandler(new XMLValidEventHandler());
db = (PoiList) unmarshaller.unmarshal(new File("src/com/sem/server/source.xml"));
} catch (JAXBException e) {
e.printStackTrace();
}
return db;
}
java.security.AccessControlException: access denied (java.io.FilePermission \WEB-INF\classes\com\sem\server read)
cheers hoax
I think the problem is that you're trying to read a file that is not located in your working directory. The guidlines for structuring your code in gwt apps are as follows
Under the main project directory
create the following directories:
src folder - contains production Java source
war folder - your web app; contains static resources as well as compiled output
test folder - (optional) JUnit test code would go here
Try moving the file to the war directory (for example /war/resources/myFile.xml) and then open it by
File myFile = new File(System.getProperty("user.dir") + "/resources/myFile.xml");
Usually, when you load a resource that is located in your classpath, you should't use java.io.File. Why? Because it's very much possible, that there is no real file - the classes are often packaged as a .jar file, or even loaded in a completely different way (very likely in the case of AppEngine, though I don't know the details.)
So, if you want to load it directly from your classpath, you can use:
ClassLoader classLoader =
getClass().getClassLoader(); // Or some other way to
// get the correct ClassLoader
InputStream is = classloader.getResourceAsStream("/com/sem/server/source.xml");
Then you can use the input stream in your unmarshaller.