I am trying to load "-javaagent:aspectjweaver1.9.1.jar" using VirualMachine. Below is the code
static {
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
int p = nameOfRunningVM.indexOf('#');
String pid = nameOfRunningVM.substring(0, p);
try {
VirtualMachine vm = VirtualMachine.attach(pid);
vm.loadAgent("C:\\Users\\mehaboobkhan.p\\Desktop\\Project\\trunk\\Batches\\LookAhead\\lib\\aspectjweaver-1.9.1.jar");
vm.detach();
List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
} catch (Exception e) {
e.printStackTrace();
}
}
I am checking the if the agent is being loaded using getInputArguments and it has not. There is not error. I am using Java8.
I checked many similar question but unable to solve it. There ever possible paths of jar (relative and absolute).
Related
`Whenever, I try to run below method it is giving above error
public static List<Product> productGettingWithSize(int size) {
Session session = factory.openSession();
List<Product> list = null;
try {
Criteria criteria = session.createCriteria(Product.class);
criteria.add(Restrictions.sizeEq("productName", size));
list = criteria.list();
if (list.isEmpty()) {
System.out.println("No Data Found..!!");
} else {
System.out.println(list);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
So, here in this code in DB productName is REDMI so, I m passing 5 as an size but, I m not getting the expected output.
So could anyone help me regarding this code or Can any anyone Tell how to use Restrictions(Size), all method related to size or can anyone send me the documentation where it is been explained explicitly.
Thank You...!!!
Expecting a solution on This..!!`
In my project, we are using the pdfbox library 2.0 version to manipulate the pdf operations.
Among those in one operation, I have a pdf file having two images on-page. Now what I have to do is,
remove one specific image from two images and keep others as is and save the document. But with the code provided in the below link it removing all images from the page.
The expected behavior should be shared in the below link. Please help me with this as I have already spent 3-4 days to achieve this.
delete am image from a PDF file using PDFbox
public void removeImages() {
try {
PDDocument document = PDDocument.load(new File("..\\sampleWithImage_with_barcode_img.pdf"));
PDPageTree page = document.getDocumentCatalog().getPages();
for (PDPage pdPage : page) {
removeQRCodeImage(pdPage, SOME_UNIQUE_ID);
}
}
document.save("..\\RemoveImage.pdf");
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void removeQRCodeImage(PDPage pdPage, String imgUniqueId) {
try {
PDResources pdResources = pdPage.getResources();
for (COSName c : pdResources.getXObjectNames()) {
PDXObject o = pdResources.getXObject(c);
if (o instanceof PDImageXObject) {
PDImageXObject pdImageXObject = (PDImageXObject) o;
if (pdImageXObject.getMetadata() != null) {
DomXmpParser xmpParser = new DomXmpParser();
XMPMetadata xmpMetadata = xmpParser.parse(pdImageXObject.getMetadata().toByteArray());
if(imgUniqueId.equals(xmpMetadata.getDublinCoreSchema().getTitle()))
((COSDictionary) pdResources.getCOSObject().getDictionaryObject(COSName.XOBJECT)).removeItem(c);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Tried Other Solution (By adding only required resources on page):
PDResources resources = copyResources(page);
COSDictionary pageObjects = (COSDictionary) resources.getCOSObject().getDictionaryObject(COSName.XOBJECT);
COSDictionary newObjects = new COSDictionary();
Set<String> imageNames = findImageNames(page);
Iterable<COSName> xObjectNames = resources.getXObjectNames();
for (COSName xObjectName : xObjectNames) {
System.out.println(xObjectName);
if (resources.isImageXObject(xObjectName)) {
Boolean used = imageNames.contains(xObjectName);
if (used) {
newObjects.setItem(xObjectName, pageObjects.getItem(xObjectName));
} else {
System.out.println("Found unused image: name={}"+xObjectName.getName());
}
} else {
newObjects.setItem(xObjectName, pageObjects.getItem(xObjectName));
}
}
resources.getCOSObject().setItem(COSName.XOBJECT, newObjects);
page.setResources(resources);
String targetRptFile = System.getenv("LOCAL_BIRT_INPUT") + "/"+report.getMergeRptTemplates().getTargetTemplate()+".rptdesign";
String attachRptFile = System.getenv("LOCAL_BIRT_INPUT") + "/"+report.getMergeRptTemplates()
.getAttachTemplate()+".rptdesign";
DesignConfig dConfig = new DesignConfig();
IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
IDesignEngine dEngine = factory.createDesignEngine(dConfig);
SessionHandle session = dEngine.newSessionHandle(null);
ReportDesignHandle targetRptDesignHandle = null;
ReportDesignHandle attachRptDesignHandle = null;
try {
targetRptDesignHandle = session.openDesign(targetRptFile);
attachRptDesignHandle = session.openDesign(attachRptFile);
} catch (DesignFileException e) {
e.printStackTrace();
}
OdaDataSourceHandle attachOdaDataSourceHandle = (OdaDataSourceHandle)attachRptDesignHandle.getAllDataSources()
.get(0);
targetRptDesignHandle.getAllDataSources().add(attachOdaDataSourceHandle);
String newTargetRptFile = System.getenv("LOCAL_BIRT_INPUT") + "/"+report
.getMergeRptTemplates().getTargetTemplate()+"-merge"+".rptdesign";
try {
targetRptDesignHandle.saveAs(newTargetRptFile);
targetRptDesignHandle.close();
attachRptDesignHandle.close();
session.closeAll(true);
} catch (IOException e) {
e.printStackTrace();
}
}
Never did this, but I remember a similar problem when I wanted to copy a JDBCDataSource. I worked around this by setting all the properties manually instead of trying to copy the whole DS.
I'm following this tutorial and I'm stuck at the part where the TwitterAcces class (that contains the twitter token) is serialized. This is where the serialization method is called:
void CallBackVerifiedResponse(OAuthAccessToken at, TwitterResponse response)
{
if (at != null)
{
SerializeHelper.SaveSetting<TwitterAccess>("TwitterAccess", new TwitterAccess
{
AccessToken = at.Token,
AccessTokenSecret = at.TokenSecret,
ScreenName = at.ScreenName,
UserId = at.UserId.ToString()
});
}
}
And this is my SerializeHelper.cs:
public class SerializeHelper
{
public static void SaveSetting<T>(string fileName, T dataToSave)
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
using (var stream = store.CreateFile(fileName))
{
var serializer = new DataContractSerializer(typeof(T));
serializer.WriteObject(stream, dataToSave);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
}
}
}
The error I'm getting is: The type or namespace name 'DataContractSerializer' could not be found (are you missing a using directive or an assembly reference?) Visual Studio can't help me resolve the problem. It suggests creating a new class. I googled around and I think the class should be inside System.Runtime.Serialization; which I am using but that doesn't solve the problem.
You got to add System.Runtime.Serialization.dll referenced in your project.
I want to get the XML in atom format of a GoogleDocs spreadsheet using the [generateAtom(..,..)][1] method of the class BaseEntry which a SpreadsheetEntry inherits. But I don't understand the the second parameter in the method, ExtensionProfile. What is it and will this method call suffice if I just want to get the XML in atom format?
XmlWriter x = new XmlWriter();
spreadSheetEntry.generateAtom(x,new ExtensionProfile());
[1]: http://code.google.com/apis/gdata/javadoc/com/google/gdata/data/BaseEntry.html#generateAtom(com.google.gdata.util.common.xml.XmlWriter, com.google.gdata.data.ExtensionProfile)
From the JavaDoc for ExtensionProfile:
A profile is a set of allowed
extensions for each type together with
additional properties.
Usually if you've got a service, you can ask that for its extension profile using Service.getExtensionProfile().
Elaborating Jon Skeet's answer, you need to instanciate a service like this:
String developer_key = "mySecretDeveloperKey";
String client_id = "myApplicationsClientId";
YouTubeService service = new YouTubeService(client_id, developer_key);
Then you can write to a file using the extension profile of your service:
static void write_video_entry(VideoEntry video_entry) {
try {
String cache_file_path = Layout.get_cache_file_path(video_entry);
File cache_file = new File(cache_file_path);
Writer writer = new FileWriter(cache_file);
XmlWriter xml_writer = new XmlWriter(writer);
ExtensionProfile extension_profile = service.getExtensionProfile();
video_entry.generateAtom(xml_writer, extension_profile);
xml_writer.close();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Analogously, you can read a file using the extension profile of your service:
static VideoFeed read_video_feed(File cache_file_file) {
VideoFeed video_feed = new VideoFeed();
try {
InputStream input_stream = new FileInputStream(cache_file_file);
ExtensionProfile extension_profile = service.getExtensionProfile();
try {
video_feed.parseAtom(extension_profile, input_stream);
} catch (ParseException e) {
e.printStackTrace();
}
input_stream.close();
} catch (IOException e) {
e.printStackTrace();
}
return video_feed;
}