I have the following Powershell code:
Add-Type -Assembly System.Configuration
[ExeConfigurationFileMap] $configMap = New-Object ExeConfigurationFileMap
All I want to do is create a new instance of ExeConfigurationFileMap, but each and every way I try, PS keeps telling me that it cannot find the type ExeConfigurationFileMap and that I should check the type's assembly is loaded into memory.
I've tried different ways of loading the System.Configuration assembly into memory, but the code still fails to work.
Could someone please assist me with this please?
try:
$configMap = New-Object -TypeName System.Configuration.ExeConfigurationFileMap
You need to specify the full type name e.g.:
New-Object System.Configuration.ExeConfigurationFileMap
Technically you don't have to provide the System. because PowerShell will prepend that if it fails to find the specified type.
Related
I have this kind of code in a ./src folder:
var fs = require('fs')
var config = require("../config.json")
when run flow, it has this error:
var config = require("../config.json")
^^^^^^^^^^^^^^^^^^ ../config.json. Required module not found
to me, that's a valid statement because the final version will be in a folder with that config.json, is there a way to instruct flowtype not checking this type of error?
Thanks
You could make flow ignore all json files by adding the following to your .flowconfig:
[ignore]
.*\.json
If you want the json file to be checked as well, you could use module.name_mapper to map to the location of your json file. Flow automatically checks required json files.
It would looks something like:
module.name_mapper='^\(.*\)\.json$' -> '<PROJECT_ROOT>/path/to/json/files'
I wrote a sample Android app. I am getting 'Tesseract(native): Could not initialize Tesseract API with language=eng!' error.
I did include
compile 'com.rmtheis:tess-two:5.4.0'
in the gradle file
Also copied all 'data files' 3.04.00 version to 'tessdata' directory.
I debugged Java portion of 'init' code it seems to be working fine, it's failing inside 'nativeside'.
Any suggestions what could be going wrong with my code. Here are few lines of code I am using to init
final String lang = "eng";
TessBaseAPI baseApi = new TessBaseAPI();
File externalDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String externalDirPath = externalDir.getAbsolutePath() + "/";
flag = baseApi.init(externalDirPath, lang);
The problem was not with tess-two, it was with my app, I deployed it on Marshmallow, it requires different way to get WRITE_EXTERNAL_STORAGE permission. I was not aware of it, now I fixed that issue my app is working fine.
I am trying to access static resource (eg. first.html) packed inside the same .jar file (testJetty.jar), which also has a class which starts the jetty (v.8) server (MainTest.java). I am unable to set the resource base correctly.
The structure of my jar file (testJetty.jar):
testJetty.jar
first.html
MainTest.java
==
Works fine on local machine, but when I wrap it in jar file and then run it, it doesn't work, giving "404: File not found" error.
I tried to set the resourcebase with the following values, all of which failed:
a) Tried setting it to .
resource_handler.setResourceBase("."); // Results in directory containing the jar file, D:\Work\eclipseworkspace\testJettyResult
b) Tried getting it from getResource
ClassLoader loader = this.getClass().getClassLoader();
File indexLoc = new File(loader.getResource("first.html").getFile());
String htmlLoc = indexLoc.getAbsolutePath();
resource_handler.setResourceBase(htmloc); // Results in D:\Work\eclipseworkspace\testJettyResult\file:\D:\Work\eclipseworkspace\testJettyResult\testJetty1.jar!\first.html
c) Tried getting the webdir
String webDir = this.getClass().getProtectionDomain()
.getCodeSource().getLocation().toExternalForm();
resource_handler.setResourceBase(webdir); // Results in D:/Work/eclipseworkspace/testJettyResult/testJetty1.jar
None of these 3 approaches worked.
Any help or alternative would be appreciated
Thanks
abbas
The solutions provided in this thread work but I think some clarity to the solution could be useful.
If you are building a fat jar and use the ProtectionDomain way you may hit some issues because you are loading the whole jar!
class.getProtectionDomain().getCodeSource().getLocation().toExternalForm();
So the better solution is the other provided solution
contextHandler.setResourceBase(
YourClass.class
.getClassLoader()
.getResource("WEB-INF")
.toExternalForm());
The problem here is if you are building a fat jar you are not really dumping your webapp resources into WEB-INF but are probably going into the root of the jar, so a simple workaround is to create a folder XXX and use the second approach as follows:
contextHandler.setResourceBase(
YourClass.class
.getClassLoader()
.getResource("XXX")
.toExternalForm());
Or change your build tool to export the webapp files into that given directory. Maybe Maven does this on a Jar for you but gradle does not.
Not unusually, I found a solution to my problem. The 3rd approach mentioned by Stephen in Embedded Jetty : how to use a .war that is included in the .jar from which Jetty starts? worked!
So, I changed from Resource_handler to WebAppContext, where WebAppContext is pointing to the same jar (testJetty.jar) and it worked!
String webDir = MainTest.class.getProtectionDomain()
.getCodeSource().getLocation().toExternalForm(); ; // Results in D:/Work/eclipseworkspace/testJettyResult/testJetty.jar
WebAppContext webappContext = new WebAppContext(webDir, "/");
It looks like ClassLoader.getResource does not understand an empty string or . or / as an argument. In my jar file I had to move all stuf to WEB-INF(any other wrapping dir will do). So the code looks like
contextHandler.setResourceBase(EmbeddedJetty.class.getClassLoader().getResource("WEB-INF").toExternalForm());
so the context looks like this then:
ContextHandler:744 - Started o.e.j.w.WebAppContext#48b3806{/,jar:file:/Users/xxx/projects/dropbox/ui/target/ui-1.0-SNAPSHOT.jar!/WEB-INF,AVAILABLE}
I am trying to execute a custom jar file from the modified javascript value. My Jar name is JsonParsing.jar which I have placed in lib folder. When I am trying to execute a method in the jar its giving me the error:
ReferenceError: "JsonParsing" is not defined.
Code Snippet:
var package1 = JsonParsing.parseJson.ParseJSON;
xyz=package1.processJson(data);
The Javascript kettle uses is Rhino. Rhino gives Javascript access to Java classes, but it's not completely transparent.
Check out the Rhino docs on Scripting Java.
I have resolved the issue. I was missing the Packages thing while creating the instance. As I had a static method in my class I have to call it in the following way. (parseJson is my package name and ParseJSON is my class name) . Here Packages is the default class provided by Rhino
var call = Packages.parseJson.ParseJSON;
xyz=call.processJson(data);
If it is a non static method I had to create an object in the following way
var call = new Pakages.parseJson.ParseJSON();
xyz=call.processJson(data);
has anyone tried to use a log4j.xml reference within a WinRun4j service configuration. here is a copy of my service.ini file. I have tried many configuration combinations. this is just my latest attempt
service.class=org.boris.winrun4j.MainService
service.id=SimpleBacnetIpDataTransfer
service.name=Simple Backnet IP DataTransfer Service
service.description=This is the service for the Simple Backnet IP DataTransfer.
service.startup=auto
classpath.1=C:\Inbox\DataTransferClient-1.0-SNAPSHOT-jar-with-dependencies.jar
classpath.2=WinRun4J.jar
classpath.3=C:\Inbox\log4j-1.2.16.jar
arg.1=C:\Inbox\DataTransferClient.xml
log=C:\WinRun4J-Service\SimpleBacnetIpDataTransfer\NBP-DT-service.log
log.overwrite=true
log.roll.size=10MB
[MainService]
class=com.shiftenergy.ws.App
vmarg.1=-Xdebug
vmarg.2=-Xnoagent
vmarg.3=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
vmarg.4=-Dlog4j.configuration=file:C:\Inbox\log4j.xml
within the log4j.xml file, there is reference to a log file for when the application runs. if I run the java -jar -Dlog4j.configuration=file:C:\Inbox\log4j.xml ...., the log file is created accordingly. if I register my service and start the service, the log file does not get created.
has anyone had success using the -D log4j configuration, using winrun4j?
thanks
I think that you provided the vmarg.4 parameter incorrectly. In your case it has to be like:
vmarg.4=-Dlog4j.configurationFile=[Path for log4j.xml]
I am also using the same and in my case, it is working perfectly fine. Please see below example:
vmarg.1=-Dlog4j.configurationFile=.\log4j2.xml
Have you tried setting the path in your code instead:
System.setProperty("log4j.configurationFile", "config/log4j.xml");
I'm using a relative path to a folder named config that contains log4j.xml. An absolute path is not recommended, but may work as well.
Just be sure to set this before making any calls to log4j, including any log4j config settings or static method calls!
System.setProperty("log4j.configurationFile", "config/log4j.xml");
final Logger log = Logger.getLogger(Main.class);
log.info("Starting up");
I didn't specify the log4j path in the ini file, only placed log4j.xml file at the same place the jar was placed.
Also without specify the
System.setProperty("log4j.configurationFile", "config/log4j.xml");
In the Java project it was stored in (src/main/resources) and will be included in the jar, but it will not be that one used if placed outside the jar.