java.lang.SecurityException:禁止的包名:java.lang

时间:2010-08-16 07:02:42

标签: java web-services ant

我在尝试构建非常简单的Web服务项目时遇到以下错误。我已经给出了build.xml,我的java文件和路径值

正在生成类文件,但未生成服务。

请帮忙......这是一个浪漫时间的烦恼..

谢谢! :)

  

CLASSPATH = C:\ BEA \ weblogic81 \服务器\ lib中\ weblogic.jar中; C:\ BEA \ weblogic81 \服务器\ lib中   \ webservices.jar; C:\ BEA \ weblogic81 \服务器\ lib中\ ojdbc14.jar的; C:\ j2sdk1.4.2_18 \ JRE \升   IB \ rt.jar中; C:\蚂蚁\阿帕奇-ANT-1.5.4 \ lib中\的ant.jar; C:\蚂蚁\阿帕奇-ANT-1.5.4 \ lib中\选项   al.jar;

     

Path = C:\ Program Files \ Reflection; C:\ oracle \ ora92 \ bin; C:\ Program Files \ Oracle \ jre   \ 1.3.1 \ bin; C:\ Program Files \ Oracle \ jre \ 1.1.8 \ bin; C:\ WINDOWS \ system32; C:\ WINDOWS;   C:\ WINDOWS \ System32 \ Wbem; C:\ Program Files \ Intel \ DMIX; C:\ Program Files \ Windows Im   老化\; C:\ j2sdk1.4.2_18 \ BIN; C:\ j2sdk1.4.2_18 \ BIN; C:\蚂蚁\ Apache的蚂蚁1.5.4 \ BIN;   PATHEXT = .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS; .JSE; .WSF; .WSH


UserModel.java

import java.sql.*;
import java.util.*;

public class UserModel
{


    Connection con=null;

    Statement st=null;
    Statement st1=null;
    ResultSet rs=null;
    String nm,age,course,address,mob,IdNum1;
    int IdNum,id;
    int x;
    int check=0;
    ArrayList list=new ArrayList();
    ArrayList eptylist=new ArrayList();
    UserModel() 
    {
    }

    public int insert(String name,String age,String course,String address,int Mob) throws  SQLException, ClassNotFoundException 

    {
        Class.forName("oracle.jdbc.driver.OracleDriver"); 
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.142.22:40401:MKTMRM9","mrm2","Marms*123.");

          st=con.createStatement();

          x= st.executeUpdate("insert into student values(seqno.nextval,'"+name+"','"+age+"','"+course+"','"+address+"','"+Mob+"')");

          if(x==1)
        {
        st1=con.createStatement();       
         rs=st.executeQuery("select seqno.currval from student");

          while(rs.next())
          {   

              IdNum=rs.getInt(1);

          }
        return IdNum;

        }
               else
        return 0;

    }   

    public ArrayList getDetails(int id1) throws  SQLException, ClassNotFoundException
    {
        Class.forName("oracle.jdbc.driver.OracleDriver"); 
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.142.22:40401:MKTMRM9","mrm2","Marms*123.");
        st=con.createStatement();
        rs=st.executeQuery("select * from student where StudentId="+id1);
        while(rs.next())
        {
            check++;
            id=rs.getInt(1);
            nm=rs.getString(2);
            age=rs.getString(3);
            course=rs.getString(4);
            address=rs.getString(5);
            mob=rs.getString(6);

        }

        list.add(new Integer(id));
        list.add(nm);
        list.add(age);
        list.add(course);
        list.add(address);
        list.add(mob);
        if(check!=0)
        return list;
        else 
        return eptylist; 
    }

}

的build.xml

<?xml version="1.0"?> 
<project name="WebServiceServer" default="create" basedir=".">

<taskdef name="servicegen" classname="weblogic.ant.taskdefs.webservices.servicegen.ServiceGenTask"/>


<property name="src" value=".\src"/>
<property name="build" value=".\build"/>
<property name="namespace" value="http://localhost:7001/UserModel"/>

<target name="create">

<javac srcdir="${src}" destdir="${build}" includes="**/*.java">
</javac>


<servicegen
    destEar="myWebServer.ear"
    warName="mywebserver.war"
    contextURI="WebServiceServer">

    <service
        javaClassComponents="UserModel"
        targetNamespace="${namespace}"
        serviceName="UserModel"
        serviceURI="/UserModel"
        generateTypes="True"
        expandMethods="True"
        style="rpc">
    </service>

    <classpath>
        <pathelement path="${build}"/>
        <pathelement path="${java.class.path}"/>
        <pathelement path="{lib}/ojdbc14.jar"/>
    </classpath>

</servicegen>

</target>

</project>

控制台出现

错误 - 运行ant时

    Buildfile: build.xml

    create:
        [javac] Compiling 1 source file to C:\Documents and Settings\344756\New\MyWe
    b\WebServiceServer\build
    [servicegen] Generating service "UserModel" ...
    [servicegen] java.lang.SecurityException: Prohibited package name: java.lang
    [servicegen]    at java.lang.ClassLoader.defineClass(ClassLoader.java:524)
    [servicegen]    at java.security.SecureClassLoader.defineClass(SecureClassLoader
    .java:123)
    [servicegen]    at weblogic.utils.classloaders.GenericClassLoader.findLocalClass
    (GenericClassLoader.java:476)
    [servicegen]    at weblogic.utils.classloaders.GenericClassLoader.findClass(Gene
    ricClassLoader.java:181)
    [servicegen]    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    [servicegen]    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    [servicegen]    at weblogic.utils.classloaders.GenericClassLoader.loadClass(Gene
    ricClassLoader.java:223)
    [servicegen]    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

    [servicegen]    at java.lang.Class.forName0(Native Method)
    [servicegen]    at java.lang.Class.forName(Class.java:219)
    [servicegen]    at weblogic.xml.schema.binding.internal.codegen.Compiler.loadCla
    ss(Compiler.java:641)
    [servicegen]    at weblogic.xml.schema.binding.internal.codegen.Compiler.addToMa
    pping(Compiler.java:450)
    [servicegen]    at weblogic.xml.schema.binding.internal.codegen.Compiler.compile
    (Compiler.java:175)
    [servicegen]    at weblogic.xml.schema.binding.internal.XSDTypeMappingBuilder.ma
    pClass(XSDTypeMappingBuilder.java:89)
    [servicegen]    at weblogic.xml.schema.binding.internal.XSDTypeMappingBuilder.ma
    pClass(XSDTypeMappingBuilder.java:102)
    [servicegen]    at weblogic.xml.schema.binding.internal.TypeMappingBuilderBase.a
    ddMapping(TypeMappingBuilderBase.java:180)
    [servicegen]    at weblogic.ant.taskdefs.webservices.autotype.ComponentAutoTyper
    .addMapping(ComponentAutoTyper.java:88)
    [servicegen]    at weblogic.ant.taskdefs.webservices.autotype.ComponentAutoTyper
    .mapComponent(ComponentAutoTyper.java:141)
    [servicegen]    at weblogic.ant.taskdefs.webservices.autotype.JavaAutoTyper.run(
    JavaAutoTyper.java:81)
    [servicegen]    at weblogic.ant.taskdefs.webservices.servicegen.ServiceGenTask.r
    unAutoTyper(ServiceGenTask.java:367)
    [servicegen]    at weblogic.ant.taskdefs.webservices.servicegen.ServiceGenTask.g
    enerateService(ServiceGenTask.java:313)
    [servicegen]    at weblogic.ant.taskdefs.webservices.servicegen.ServiceGenTask.e
    xecute(ServiceGenTask.java:181)
    [servicegen]    at org.apache.tools.ant.Task.perform(Task.java:341)
    [servicegen]    at org.apache.tools.ant.Target.execute(Target.java:309)
    [servicegen]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
    [servicegen]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)

    [servicegen]    at org.apache.tools.ant.Project.executeTargets(Project.java:1255
    )
    [servicegen]    at org.apache.tools.ant.Main.runBuild(Main.java:609)
    [servicegen]    at org.apache.tools.ant.Main.start(Main.java:196)
    [servicegen]    at org.apache.tools.ant.Main.main(Main.java:235)

    BUILD FAILED
    file:C:/Documents%20and%20Settings/344756/New/MyWeb/WebServiceServer/build.xml:2
    0: java.lang.SecurityException: Prohibited package name: java.lang

    Total time: 1 second

2 个答案:

答案 0 :(得分:3)

您自己的课程包含在哪个包中?

发生此错误是因为禁止将您自己的类放入包java.lang中。看起来您正在尝试编译包java.lang中的类。

如果你自己的类根本不在一个包中(你的源文件顶部没有package语句),那就把它们放在一个包中。

答案 1 :(得分:0)

如果确保项目包名称不是以Java或javax开头,请尝试使用以下方法:

当我跑步时:

mvn clean install     

CLI中的命令,它显示构建成功,当我使用Eclipse编译项目时,它显示

  

java.lang.SecurityException:禁止的包名:java.lang.annotation

但我的parnter项目是正确的,我认为这是IDE或编译环境问题,当我将jdk版本从1.8x降级到1.7x时,问题就消失了。