小编Ree*_*ore的帖子

为新注入的类设置类路径

上下文:一个新类说Bar,在运行时注入JVM.这个类属于com.foo这个包.对此类的引用将注入到属于同一包的另一个类中.每次加载时,新类可能都有不同的名称 - 因此不能将其指定为任何配置文件的一部分 - 例如,不能在build.xml中指定它作为jar文件的一部分包含在内.

问题:在类加载时,jvm会抛出一个错误 - java结果1.尽管我无法确定根本原因,但看起来类加载器找不到新注入的类.服务器以详细模式运行,该模式显示JVM加载的类列表,并且可以看到这个新注入的类已加载.

问题:新注入的类是否已经在类路径中?如果没有怎么设置呢?

[编辑] - 在问题中添加一些代码.

代码段 - 1:下面的代码段是从PreMain方法调用的 - Premain方法将由JVM代理调用,并将在运行时注入检测引用.Premain方法从一个方法中返回一个新类--Bar - 和一个对这个新类的引用 - returnsABool() - 在一个现有的类中 - ExistingClass.

public static void premain(String agentArgs, Instrumentation inst) {

        // 1. Create and load the new class - Bar
        String className = "Bar";
        byte [] b = getBytesForNewClass();
        //override classDefine (as it is protected) and define the class.
        Class clazz = null;
        try {
          ClassLoader loader = ClassLoader.getSystemClassLoader();
          Class cls = Class.forName("java.lang.ClassLoader");
          java.lang.reflect.Method method =
            cls.getDeclaredMethod("defineClass", …
Run Code Online (Sandbox Code Playgroud)

java classpath code-injection

5
推荐指数
1
解决办法
414
查看次数

如何为PHP生成的图像设置默认的"另存为"名称?

这是我的代码.

<?php
function generate_card($card_number='',$card_price='',$card_expire='',$image_path='',$font_path)
{
    // store image on variable //
    $image = imagecreatefrompng($image_path);

    // some text color
    $color = imagecolorallocate($image, 255, 255, 0);

    // print card price //
    imagettftext($image, 15, 0, 200, 40, $color, $font_path, $card_price);
    // print card number //
    imagettftext($image, 15, 0, 15, 85, $color, $font_path, $card_number);
    // print expiry date //
    imagettftext($image, 12, 0, 145, 155, $color, $font_path, $card_expire);

    header('Content-type:image/png');
    imagepng($image);
    imagedestroy($image); 
}
generate_card('1234 5678 9101 1121','$200','12/13','card.png','verdana.ttf');
?>
Run Code Online (Sandbox Code Playgroud)

我正在生成签证礼品卡,图片也在页面上创建和显示.但我的问题是,当我想在Mozilla中保存这个图像时,它会给出"page_name.png",在IE中它给了我"无标题".如何在保存时给出自己的名字,如"visa_gift_01.png".

php header

4
推荐指数
2
解决办法
4517
查看次数

为什么这个命令在这个特定代码中不起作用?

我怎么会这样呢?我试过了

Net::HTTP.new(@site).head('/').kind_of? Net::HTTPOK
Run Code Online (Sandbox Code Playgroud)

但我收到了这个:

错误:在`kind_of?'中:需要的类或模块(TypeError)

我觉得我的代码有问题,你能看一下吗?我知道它非常混乱和非常糟糕,我是一名编程学生,我正在学习.如果您有任何改进的想法,请告诉我!

此外,还有一些东西搞砸了包含在其中的目标.出于某种原因,当我尝试结束所有defs时,我得到意外的结束错误.

这是我在上下文中的代码:

def begindownload
    require 'net/http'
    puts "Enter the URL of the site that you want to rip images from (use www.*website*.com/folder/file.html or other extension format):"
    while @site = gets.chomp
        puts "Querying " + @site 
        if Net::HTTP.new(@site).head('/').kind_of? Net::HTTPOK == true
            puts "Site is online!"
        else 
            puts "Site is offline. Try again."
        end
    end
end
Run Code Online (Sandbox Code Playgroud)

ruby

4
推荐指数
1
解决办法
884
查看次数

grails不会保存,但没有错误

嗨,我有一个像下面这么简单的域名

// page 52 Bankruptcy Questions 
class FamilyLawFinancial{

    Date dateOfTheOrder ;
    boolean isPartyToFamilyLawProperty = false; 
    boolean isCurrentlyInvolvedInFamilyLawProperty = false;
    boolean isBecomeInvolvedInProceedings = false;

    static belongsTo=[person:Person];

    static constraints = {
        dateOfTheOrder(nullable:true);
        isPartyToFamilyLawProperty(nullable:false);
        isCurrentlyInvolvedInFamilyLawProperty(nullable:false);
        isBecomeInvolvedInProceedings(nullable:false);
    }

    String toString(){
        "${id}"
    }
}
Run Code Online (Sandbox Code Playgroud)

这是保存数据的控制器:

    def save = {
    def person = Person.get(session.curperson.id);
    def obj = FamilyLawFinancial.findByPerson(person);
    if(obj == null){
        obj = new FamilyLawFinancial();
        obj.person = person ; 
    }
    params.dateOfTheOrder = myutil.formatDate(params.dateOfTheOrder);
    obj.properties = params;

    println(obj.hasErrors());
    println(obj.dateOfTheOrder);
    if(obj.hasErrors() && !obj.save(flush:true)){
        println("errors: ${obj.errors}");
        flash.message = "error …
Run Code Online (Sandbox Code Playgroud)

java grails java-ee grails-domain-class

3
推荐指数
1
解决办法
1585
查看次数

在Linux中的Ucontext

我读到ucontext用于在linux中的多个线程之间保存上下文.由于操作系统在不同线程之间进行上下文切换,为什么linux提供此头文件(ucontext.h)进行上下文切换?

c linux ucontext

3
推荐指数
1
解决办法
7074
查看次数

如何在C#中找到多个

我怎么能在if语句中找出天气指定的int是5的倍数?这就是我的意思:

if(X [is a multiple of] 5)
{
    Console.Writeline("Yes");
}
Run Code Online (Sandbox Code Playgroud)

会是什么[是倍数]?

另外,为什么当我这样做时:

if(X = 5)
{
    Console.Writeline("sdjfdslf");
}
Run Code Online (Sandbox Code Playgroud)

它以红色显示"X = 5"并告诉我"不能隐式转换类型"int"到"bool"?我使用X作为输入.

c#

2
推荐指数
2
解决办法
6916
查看次数

math.random假定0是一个整数吗?

那么,确实int random = (int) Math.ceil(Math.random() * 5);返回0,1,2,3,4而不是1,2,3,4,5的值吗?

我试图测试这个,但它似乎永远不会达到0或5 = x

random math android

0
推荐指数
1
解决办法
1107
查看次数

如何从命令提示符获取输出并使用语言Java创建一个文本文件

这就是我所发现的,但是在这段代码中,它会读取你输入的内容,我不希望这样

我正在做一个名为Knight's Tour的程序,我在命令提示符下输出.我想要做的就是从命令提示符中读取行并将其存储为名为knight.txt的输出文件.谁能帮我吗.谢谢.

try
{
    //create a buffered reader that connects to the console, we use it so we can read lines
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    //read a line from the console
    String lineFromInput = in.readLine();

    //create an print writer for writing to a file
    PrintWriter out = new PrintWriter(new FileWriter("output.txt"));

    //output to the file a line
    out.println(lineFromInput);

    //close the file (VERY IMPORTANT!)
    out.close();
}

catch(IOException e)
{
    System.out.println("Error during reading/writing");
}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
3328
查看次数

当我从主菜单中选择我得到:game.sh:423:语法错误:文件结束意外(期待"fi")

!# /bin/sh
# game.sh: 
#  Chooses games based on genre and title
#  Also Shows descriptions of games

# Genre Menu
clear
printf "%s\n" "Game genre Menu"
printf "%s\n"
printf "%s\n" "1. First Person Shooter"
printf "%s\n" "2. Arcade"
printf "%s\n" "3. RPG"
printf "%s\n" "4. RPG (Infocom A-Jo)" #1-12
printf "%s\n" "5. RPG (Infocom Le-St)" #13-24
printf "%s\n" "6. RPG (Infocom Su-Zo)" #25-36
printf "%s\n" "7. RPG (Infocom ZZinvisiclues)" #37-45
read -p "Enter Number: " GENRE
 if [ $GENRE …
Run Code Online (Sandbox Code Playgroud)

bash shell

-1
推荐指数
1
解决办法
271
查看次数