Packages, classpath, sigh...

I have a package, which has different versions for mac and windows. So, I thought I would make 2 folders one called "mac" and one called "win" and stick the corresponding package version into each folder along with shared library files for the OS. Depending on which OS the program is running on, I would set the classpath and library path to either "mac" or "win." However, even though both the classpath and libpath ARE being set correctly (I've checked them with println's) the prog cannot find the classes in the package.
The strange thing is, if I'm on say for instance "mac" os, and I place the macos package AND macos sharedlibrary into my CURRENT directory(along with all my classes and src files) and I set the CLASS and LIBRARY paths to THAT directory, the program finds the package and the lib without a problem and the program runs. I think my problem is that when I put a package into a folder, that folder actually becomes part of the fully qualified package name even though I didn't declare it that way with my package statement in my classes... Or something to do with placing a package into a folder that I cannot figure out. Any of you guys able to help me? Here's some code snippets...
This sets class and lib to current dir and works
import java.io.File;
import java.io.IOException;
public class PathSetter
     PathSetter()
        try
            String classpath = System.getProperty("java.class.path");
            String libpath = System.getProperty("java.library.path");
            File thisDir = new File (".");
               String pathSep = System.getProperty("path.separator");
               String[] dirs1 = classpath.split(pathSep);
               String[] dirs2 = libpath.split(pathSep);
               boolean classThere = false;
               boolean libThere = false;
               for(int i = 0; i < dirs1.length; i++)
                    if(dirs1.equals(thisDir.getCanonicalPath()))
                         classThere = true;
                         break;
          for(int i = 0; i < dirs2.length; i++)
                    if(dirs2[i].equals(thisDir.getCanonicalPath()))
                         libThere = true;
                         break;
          if(classThere == false)
               String currentDir = thisDir.getCanonicalPath();
                    System.setProperty("java.class.path", classpath + pathSep + currentDir + pathSep);
               if(libThere == false)
               String currentDir = thisDir.getCanonicalPath();
                    System.setProperty("java.library.path", libpath + pathSep + currentDir + pathSep);
     catch(IOException e){ e.printStackTrace(); }
This sets class and lib to corresponding OS folder, and DOES NOT work
import java.io.File;
import java.io.IOException;
public class PathSetter
     PathSetter()
        try
            String classpath = System.getProperty("java.class.path");
            String libpath = System.getProperty("java.library.path");
            String pathSep = System.getProperty("path.separator");
            String os = System.getProperty("os.name");
            String firstThree = os.substring(0, 3);
            File thisDir = new File (".");
            File newDir = null;
               String[] dirs1 = classpath.split(pathSep);
               String[] dirs2 = libpath.split(pathSep);
               boolean classThere = false;
               boolean libThere = false;
               if(firstThree.equalsIgnoreCase("win") == true)
               { newDir = new File(thisDir.getCanonicalPath() + System.getProperty("file.separator") + "win"); }
               else if(firstThree.equalsIgnoreCase("mac") == true)
               { newDir = new File(thisDir.getCanonicalPath() + System.getProperty("file.separator") + "mac"); }
               for(int i = 0; i < dirs1.length; i++)
                    if(dirs1.equals(newDir.getCanonicalPath()))
                         classThere = true;
                         break;
          for(int i = 0; i < dirs2.length; i++)
                    if(dirs2[i].equals(newDir.getCanonicalPath()))
                         libThere = true;
                         break;
          if(classThere == false)
               String correctDir = newDir.getCanonicalPath();
                    System.setProperty("java.class.path", classpath + pathSep + correctDir + pathSep);
               if(libThere == false)
               String correctDir = newDir.getCanonicalPath();
                    System.setProperty("java.library.path", libpath + pathSep + correctDir + pathSep);
     catch(IOException e){ e.printStackTrace(); }

Ok heres the setup.
In my "main" folder I have all class and source files. This folder is called "test."
Within that folder along with class/src files are 2 folders called "mac" and "win"
Inside "mac" is the mac version of the package "org.eclipse.swt" and also the mac shared library.
Inside "win" is the windows version of "org.eclipse.swt" and also the windows .dll files.
First I run the pathsetter class in the snippets I originally posted. Setting the class and lib paths to either "mac" or "win."
Then from classes in the "test" folder, I have import statements like "import org.eclipse.swt.graphics.*, import org.eclipse.swt.events.*, etc. Because only one of the "mac"/"win" folders is in the class/lib paths, those import statements should import the correct packages. i.e. If I'm on mac, it should import the package in the "mac" folder because that is the only place it knows to look.
Does this help? The problem I was running into was finding a way to determine which OS I was on, and then be able to import the correct package and lib files after making that determination. The only way I could think to do this was to make the 2 folders and set classpath and libpath.

Similar Messages

  • Packages, Classpath, Ant, and JUnit (setting up a nice environment)

    Hi,
    I am seeking a little help getting up and running, creating a nice environment where I can build a Java project, including building with Ant and using JUnit - hopefully this is the right forum. I am having some trouble in getting JUnit to run my tests properly (it is installed and findable by my Java install) and I think this is due to a package/classpath issue that is currently outside my experience. Here's my setup to explain:
    I have installed the JUnit jar in my extensions folder, and it works properly (I can call it, don't get errors about JUnit), however, when I run my test I get the error:
    "Could not find class: org.xxx.powersim.ModelTest
    Time: 0
    OK (0 tests)
    Java Result: 1"
    ModelTest has been compiled properly without error, and looks like this:
    package org.xxx.powersim;
    import org.junit.*;
    import static org.junit.Assert.*;
    import java.util.*;
    public final class ModelTest {
         public static void main(String args[]) {
               org.junit.runner.JUnitCore.main("org.xxx.powersim.ModelTest");
         @Test
         public void testJunit() {
              assertTrue(true);
    }Pretty simple stuff.
    As you can see I'm trying to use the 'main' method of the test to execute the test itself... but I've tried running it via the runner from the command line also: "java org.junit.runner.JUnitCore org.xxx.powersim.ModelTest". I get the same result.
    It might be a package issue, so here's how I have things set up in the file system:
    PowerSim
         /build
              /org
                   /xxx
                        /powersim
                             - ModelTest.class
         /src
              /org
                   /xxx
                        /powersim
                             -ModelTest.javaI've tried running it within Ant, by hand using the runner, by hand calling the main method, and from within TextMate's built-in bundle - I get the same result. JUnit is installed and running fine, but it can't seem to see the test class - the more I think about it this is a package problem that I'm just not sure how to fix. I've tried running it by hand in the root /PowerSim directory, in the /build folder, and in the /powersim folder where ModelTest is. I still get the error that "Could not find class: org.xxx.powersim.ModelTest".
    My files compile just fine with my simple Ant script which is as follows:
    <?xml version="1.0"?>
    <project name="PowerSim" default="run" basedir=".">
    <property name="src" value="./src"/>
    <property name="build" value="./build"/>
    <property name="compile.debug"       value="true"/>
    <path id="compile.classpath">
       <pathelement location="${mysql.jdbc}"/>
       <pathelement location="${junit.jar}"/>
    </path>
       <target name="build" depends="init">
           <javac srcdir="${src}"
                  destdir="${build}"
                  debug="${compile.debug}"
                  source="1.5">
              <classpath refid="compile.classpath"/>
           </javac>
       </target>
    <target name="init">
       <mkdir dir="${build}"/>
    </target>
    <target name="run" depends="build">
       <java classname="org.xxx.powersim.Model"
           fork="true"
           dir="${build}"
           classpath="${build}"
           maxmemory="500m">
       </java>
       </target>
         <target name="test" depends="build">
             <java classname="org.xxx.powersim.ModelTest"
                 fork="yes"
                 dir="${build}"
                 classpath="${build}"
                 maxmemory="500m">
             </java>
             </target>
    <target name="clean" description="Removes previous build">
       <delete verbose="true">
         <fileset dir="${build}"/>
       </delete>
    </target>
    </project>As you can see, I'm not sure what to try next - any help would be much appreciated.
    I've tried adding things to my $CLASSPATH. For example I've added the root folder of the project, 'PowerSim' to my classpath, but this appears to have no effect. I am running OS X 10.5.
    Thanks again for any help you may be able to offer, it will be very much appreciated,
    - Peter

    Ok - final bump and then I'll go away.
    (Really - if anyone has any advice that would be great)

  • Package/Classpath problem with 1.4

    I've two classes. one class has a package structure and other does not. when i try to compile the class (having package structure) which has a reference to other class (which doesn't have package structure), I get error "cannot resolve symbol"
    eg.
    package com.hamilsci;
    public class A {
    public A() {
    B obj = new B();
    class A is in dir /usr/local/java/examples
    public class B {
    public B() { }
    class B is in dir /usr/local/java/helperclasses and doesnot have package structure
    When I tried to compile A without the package statement, everything works fine. But when I add package structure to Class A, I cannot compile . The error Message is :cannot resolve symbol
    symbol : class B
    location: class com.hamilsci.A
    B obj = new B();
    ^
    I'm using JDK1.4 and I've tried setting the CLASSPATH.
    Any help would be highly appreciated.
    -Thanks
    -Mike

    Here's a tutorial on packages.
    http://java.sun.com/docs/books/tutorial/java/interpack/packages.html
    If you have a class with "package com.hamilsci" it must be in a directory named hamilsci, hamilsci must be in a directory named com, and com must be in a directory that is in your classpath.

  • Packages, classpath in xcode

    hello,
    I've recently started using xcode (on Mac OS X) to develop java apps. I want to include a package or just some indiviudal classes, but don't know how. How do you specify the CLASSPATH in xcode?
    I've tried putting them in ~/Library/Java/Extensions, but this doesn't seem to work.
    any help?
    George

    You could try setting JAVA_CLASS_SEARCH_PATHS in the project build settings. I haven't used XCode for Java projects yet (only C/C++) but perhaps reading through the old Java doc for Project Builder may help:
    http://developer.apple.com/documentation/Java/Conceptual/Project_Builder_for_Java/
    There's also an Xcode users mailing list hosted by Apple:
    http://lists.apple.com/mailman/listinfo/xcode-users

  • Packages & classpath on os x

    Hi,
    I had some questions about where i should be putting class files. i've got files in a package com.one2one3.io, so i've got a directory structure /com/one2one3/io/ and i'm wondering where is the generally accepted place to put that, its working for now in ~/Code/com/one2one3/..., but then i have to specify the classpath everytime i compile...
    that brings me to the question of setting the classpath in my .tcshrc file so i don't need to do that everytime... google says this should work:
    setenv CLASSPATH .:/Users/stephen/Code/:${CLASSPATH}
    but it isn't i still get class not found errors when compiling.
    can i put the packages i write in /Library/Java/Extensions/com/one2one3/...? from what i understand the jvm on mac searches there by default so i wouldn't need to specify the classpath everytime i compile. thats working for me, but i want to check and make sure it won't cause me any problems down the line...i guess mainly i'm wondering what you all do to deal with these things.
    and is it usual to include the source .java files in the /com/one2one3/... directory?
    Stephen

    I'm relatively new to Java in general, but I've been developing on Linux and Mac OS X a bit and I have some thoughts I can share. Someone will jump in here and correct me if I'm wrong. But I think I've got it. In any case here is a web page you may find helpful on the javac command.
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html
    And here is a link to a relevant thread in the forum discussing the classpath on OS X.
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=570279
    I had some questions about where i should be putting class files. I generally let the compiler take care of where to put the class files. Of course if no direction is specified using the "-d" option with the javac command, the files will be placed inside the current working directory. That's true on all OS systems including Mac OS X.
    i've got files in a package com.one2one3.io, so i've got a directory structure
    /com/one2one3/io/ and i'm wondering where is the generally accepted place to
    put that, its working for now in ~/Code/com/one2one3/..., but then i have to
    specify the classpath everytime i compile...Note that when the source file that is being compiled includes a package declaration at the top like
    package com.one2one3.io;
    public class HelloWorld {
    }if the directive option "-d" is specified with the javac command and it points to another directory location other than the current working directory, the compiler will create a directory structure for you (assuming one does not already exist) in that destination directory which mirrors the package structure of the java file. That's quite convenient. So for example you can have all your source files in a top level working directory, like "code", and then direct the output of the javac command, the class files themselves, into another directory, maybe one called "classes".
    javac -d classes HelloWorld.javaAfter executing this you will see that the first directory inside the classes directory will be another directory called "com", consistent with your package com.
    that brings me to the question of setting the classpath in my .tcshrc file so
    i don't need to do that everytime... google says this should work:
    setenv CLASSPATH .:/Users/stephen/Code/:${CLASSPATH}
    but it isn't i still get class not found errors when compiling. Once you can isolate all of your class files into the classes directory, then you define the classpath as the classpath using the "-classpath" option of the javac command. You may want to include the current working directory too by including "./" with the option.
    javac -d classes -classpath ./:classes HelloWorld.javaNote though that when you use the -classpath option with the javac or java command, it does override whatever you currently have set in your system settings. Nonetheless, I understand that this is the standard method of defining the classpath.
    Suppose though that you have a number of different external library jar files that you need to include on the class path. Or suppose you have large numbers of source files you wish to compile all at once. In this case you may want to consider creating command line argument files, as explained here...
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html#commandlineargfile
    Then your javac command would look something like this.
    javac @options HelloWorld.javawhere your classpath and directive would be defined in a file named "options" in the current working directory.
    can i put the packages i write in /Library/Java/Extensions/com/one2one3/...?
    from what i understand the jvm on mac searches there by default so i wouldn't
    need to specify the classpath everytime i compile. thats working for me, but i
    want to check and make sure it won't cause me any problems down the line...i
    guess mainly i'm wondering what you all do to deal with these things.
    and is it usual to include the source .java files in the /com/one2one3/...
    directory? Actually I understand that it is considered poor practice to place files directly into the extensions directory of the Java directory, though you are correct about it's location on Mac OS X. It does work, but it's a bit of a cheat.

  • Package CLASSPATH

    hi folks
    i have created classes and i want to put in a package let say com.isis.graphics so i created 3 folders in order in the package name and i puted my classes in the folder graphics and in every class first line is package com.isis.graphics.and i typed in the Autoexec.bat the followoing line
    set CLASSPATH=%CLASSPATH%;c:\com\isis\graphics the problem is when i'm trying to create a new class outside the package extending a class inside the package i get Compiler Error can any one till me why!? and How to det the CLASSPATH typed in the autoexec.bat in good way?
    Please Help

    Thnx Guys
    thnx Patrick
    it worked in the case of using creating a class using
    a text editor.but i meant that how can i use this
    package from tool under windows like Forte or
    JBuilder.i tried but the (Forte or JBuilder) issue an
    Error that he doesn't know where is the package
    com.isis.javaWith Forte you have to mount the directory or jar file. If you mount the root directory as has been suggested Forte will mount not only the directory /com/isis/java, but also all the other directories under /, which is not what you desire.
    Since you're relatively new at this I assume you out of desparation 'un-jarred' the isis distribution into your file system. So the best thing to do with Forte is to MOUNT THE original isis JAR archive. In future do not unjar third party packages. They waste your disk space and cause you to lose your way in your own file system.
    So for Forte you mount the jar file with the following menu selections: FORTE=>View=>Explorer=>...FileSystems=>MountJar.
    MountJar will be in the LocalMenu of (right-click the mouse over the item ->) 'FileSystems'.
    I am not looking at the JBuilder UI as I type so I cannot be explicit in my answer, but it has a more traditional menu facility for adding third-party libraries and archives. If you have your project already loaded, there should be a place where you can change its SETTINGS such as Debug CommandLine Options,SourcePath, ClassPath, Libraries and the like. Poke around and you will find the spot where you can add the isis jar file immediately after the Sun and Borland jar and zip files. If you have cleaned up the unjar directories, just create your own third-party directory where you plunk the isis jar file. Then update the Classpath to include that thrd party directory, and then finally add the isis librar jar file name into the extra library dialogue.
    if u have a way to do this i'll be gratefull
    and thnx anywayGood luck.
    Malome

  • Cant use packages/classpaths correctly _ never could too

    Hello,
    I have a directory C:\DIR
    In this directory I have a program. Two files both declare the package a.b package a.b;. Both files are in the directory C:\DIR\a\b.
    One of my files is KeyInput.java which implements KeyListener for obvious reasons.
    The second file is Main.java which has a Frame frame to which I want to add a KeyListener: frame.addKeyListener(new KeyInput()); Now, this works perfectly fine when I have KeyInput as an inner class, but using this (the above) architecture my compiler can't find KeyInput.
    I have not set a classpath (though I did try that in my compiling command "javac -classpath C:\ Main.java", but that did not work).
    I did check all sorts of documentation on this, so please don't answer that I should do just that. I can't get it running. Until now my remedy was not using packages, but I want to.
    Please tell me what I am doing wrong,
    Q
    thanks

    I now have another basic problem with these two classes, which concerns the concept "static".
    Here's the problem:
    When I add a KeyListener to frame as above I instantiate a KeyInput.
    In KeyInput I for instance want to use a key to quit the program. (I also want a lot of other things, but
    the same problem applies to them) To do this I create a method "public void kill( )" in Main. mainInst is
    an instance of Main (created in the public static void main (String[] args) method), but my instance of KeyInput does not know him.
    So now I have a problem. Because I either have to make my instance of KeyInput know mainInst so it
    can do "mainInst.kill( )", which I do not know how to do; or I have to use the Main class itself. However:
    Main.kill( ) does not work, because kill isn't static. I could make kill static, but then I have a static context
    where I don't want any, for know I have a boolean running which has to be declared static etc. etc., and
    then I'm not even talking about all the other things to do with the keys.
    Ok, one solution is simple... make KeyInput an inner class of Main. But I don't want that! It will wreck
    all the little beauty present in my programmature. So what do I do? How does a professional do this? It's such a basic problem I must know the answer.
    Many thanks,
    Q

  • Problems with packages, classpath and BouncyCastle Library

    Hi everybody!
    Shortly, after adding BC's crypto library to my MOBILE (J2ME) project, when I build it returns a NoClassDefFoundError about java.math.BigInteger class.
    Its package is the same of J2SE but is included in this library. Now, this should not be a problem, 'cause java.math.BigInteger is not included in J2ME, and library's release is (I'm sure) for J2ME...I think it's a problem of classpath but I can't find a way to go on with my project!
    Please, if anybody knows where I'm wrong let me know!!!
    ...and sorry for my bad english...;-)
    b4kk3

    I think the update is buggy. Many people (inc. me) are having problems with it. Am not able to play any songs/videos .. terrible !

  • Remove .classpath

    Can someone help me in removing '.classpath' file from DTR? It appears that one of our developers have an exlusive lock on this file and we are unable to remove the file, which is preventing other developers from build this package. When the devlopers that is said to have an exclusive lock on this package attempts to remove the .classpath, 'delete' option is greyed out.
    Are there any work arounds to this, or is there a way to have developers build around class-path file, since every developers enviorment is different?
    This is Portal developement --Not component based.
    Error Message:
    11:48:14.266  DELETE  (FAILED: Conflict [(pre||post)-condition failed: x:concurrency-lock-denied])  .classpath   (C:\Documents and Settings\user\dtr\Admin\Development\Projects\dev\com.package\.classpath)
    Edited by: John Edwards on Feb 1, 2008 6:59 PM
    Edited by: John Edwards on Feb 1, 2008 6:59 PM

    Pascal-
    Now that I have the technical information, I have tried following this procedure Link:[http://help.sap.com/saphelp_nw04s/helpdata/en/46/f09dfed6705515e10000000a1553f6/content.htm], for deleting the activity --however I have no option as mentioned to 'revert the activity.'
    The Resource Details in DTR says: Has Foreign Checkout: Yes

  • [原创]在WLS9中使用J2EE Libraries 和 Optional Packages

    J2EE Libraries 和 Optional Packages
    概述
         J2EE Shared Libraries是Diablo的一个新特性。可以将一个J2EE模块共享给其他EAR类型的J2EE模块。你不能从非EAR访问J2EE Shared Library。J2EE Shared Library可以是任何类型的J2EE模块,但推荐打包成EAR。此外还有一种J2EE 1.4的标准共享库方式,称为 Optional Packages。区别在于 Optional Packages是基于标准的,而且不被当作J2EE模块使用。 Optional Packages提供和J2EE Libraries类似的方式将一个JAR文件被多个应用分享。optional packages必须通过部署对应的JAR文件方式先被注册到WLS。注册好后可以部署J2EE模块,通过manifest files来引用这些包。Optional packages和J2EE libraries的区别在于optional packages可以被任何J2EE模块(EAR, JAR, WAR, or RAR 文档)或扩展的目录结构引用。而J2EE libraries只能被EAR引用。
         本文附件exercise包括J2EE Libraries 和 Optional Packages的练习代码,可解压到任意位置。配置一个WLS Domain,记得用户名和密码要都设为weblogic,端口为7001。启动该Domain,并启动相应的Console。使用Domain/bin/setDomainEnv.cmd打开一个Prompt窗口。并把目录切换到你解压的文件的位置。然后就可以按照第五节和六节所述完成练习。如果想快速看一下练习结果,在solution中有已经配置好的两个练习的代码,部署后就可以测试。
    一。将一个应用作为J2EE Libraries或Optional Packages。
         你可以在该应用的META-INF目录下创建一个MANIFEST.MF文件,指定自己的版本。
         Extension-Name:可选。表示该库或包的名字。主调应用调用这个应用时需要匹配这个值。如果你不设置这个值,系统将自动使用部署名。
         Specification-Version:可选。定义这个库或包的规格版本。主调应用可以为共享模块随便指定一个规格版本。如果这个规格版本不可用,则主调应用不能被部署。规格参数可以有两种格式。第一种使用主从版本格式,大小版本号用点分割,如"9.0.1.1"。第二种使用文本格式,如 "9011Beta"。如果使用主从版本号格式,主调应用可以配置为共享的模块吻合一个特定版本,或者一个最小版本,或者一个最新的版本额。如果使用文本格式,主调应用必须和共享模块的版本号严格吻合。
         Implementation-Version:可选。定义这个库或包代码的执行版本号。必须在已经定义了规格版本的情况下才能定义执行版本。执行版本使用和规格版本相同的格式。
         如果你不使用MANIFEST.MF文件或者有些条目没有指定,可以在命令行中通过weblogic.Deploy进行部署的时候由参数来设置。
    二。J2EE Libraries and Optional Packages比较:
         Optional packages和J2EE Libraries有如下共同点:
         1。在部署的时候都注册到WLS上。
         2。都支持可选执行版本和特定版本字符串。
         3。引用J2EE libraries and optional packages的应用可以指定共享文件的版本。
         Optional packages和J2EE Libraries有如下区别:
         1。Optional package是普通的JAR文件,而 J2EE libraries可以是普通JAR文件,或J2EE应用,或独立的J2EE模块。J2EE libraries可以包括有效地J2EE或WLS部署描述符,而optional package JAR中的任何部署描述符都被忽略了。
         2。任何J2EE应用或模块可以通过META-INF/MANIFEST.MF引用 optional package。而只有企业应用可以通过weblogic-application.xml引用J2EE library 。
         3。Optional packages可以引用其他Optional packages,而J2EE libraries不能引用其他J2EE libraries。
    三。最佳实践:
         1。如果需要共享J2EE模块给多个企业应用。使用J2EE Libraries。
         2。如果要部署独立的J2EE模块作为共享库,应该把模块打包到企业应用中。这样可以防止潜在的URI冲突。因为独立模块库的URI来源于不署名。所以在部署时指定一个部署名,当其他应用引用它时作为URI。
         3。如果多个J2EE压缩文件需要共享一些JAVA类,则应该用optional packages。
         4。如果有一些类在本Domain中需要被其他应用调用,而你又不经常省级这些类(比如第三方类),则最好把它们放在Domain的 /lib目录下,而不是使用J2EE libraries或optional packages机制。在/lib子目录下的类会在Server启动时候自动装载到系统环境变量中。
         5。通常指定一个规范版本和一个执行版本。即使你不打算使用版本需要功能。为库指定版本可以在做测试时为共享的文件部署多个版本。
         6。通常为每个库指定一个扩展名,如果你不指定扩展名那系统会自动使用库的部署名作为扩展名。
         7。当开发了一个Web应用要部署成J2EE应用,应该使用唯一的上下文目录。如果它的上下文目录和他依赖的应用的上下文目录冲突,应该使用EAR的weblogic-application.xml中context-root元素来覆盖库的上下文目录。
    四。组装共享的J2EE Library 文件:
         几乎所有独立的J2EE模块或EA可以被部署成shareable J2EE library,但有如下限制:
         1。不能在一个J2EE library中引用另一个J2EE library.
         2。共享库不能嵌套。如果你不属一个EAR作为共享库,那整个这个EAR必须被作为一个库,而不能指定这个EAR中的某个独立J2EE模块为一个独立的库。
         3。像其他J2EE模块和企业应用一样,J2EE library必须被部署到目标Server或Cluster上去。这意味着库需要一个有效的J2EE部署描述符和WLS指定的部署描述符。
         4。推荐把J2EE libraries打包成企业应用,而不是独立的J2EE模块。因为独立模块的URI来自于部署名。默认WLS使用部署压缩文件的文件名或展开的目录名作为部署名。
         5。如果你选择把库部署成独立的J2EE模块,通常应该指定一个部署名并把这个名字作为被应用引用的URI。
    五。练习开发和部署Shared J2EE Library
         本练习在J2EEShared目录下。可以看到有两个目录,其中SharedLibraryEAR是被调用的shareable J2EE library,CallingLibraryEAR是调用该库的企业应用。通过把SharedLibraryEAR配置成共享库,CallingLibraryEAR可以访问LoanEJB就像打包在自己的EAR中。
         1.我们先来开发一个库应用。观察一下SharedLibraryEAR下面的目录结构和文件。
         目录LoanEJB是一个EJB结构。包括一个空的目录META-INF和一个包含一个JAVA文件Simple.java的目录data。LoanEJB\data目录是放EJB的源代码,Simple.java是我手写的。在LoanEJB下执行java com.bea.wls.ejbgen.EJBGen -descriptorDir META-INF data\Simple.java就会在生成SimpleHome.java,SimpleRemote.java,ejb-jar.xml,weblogic-ejb-jar.xml和ejbgen-build.xml。然后到LoanEJB编译这几个CLASS:javac data\*.java,生成根和桩文件。最后执行jar cvf ..\LoanEJB.jar *,打包我们需要的EJB LoanEJB.jar到SharedLibraryEAR目录。
         目录APP-INF是一个空的目录,可以放入当前这个应用需要的第三方包。
         目录META-INF下包括application.xml和weblogic-application.xml。application.xml指定了这个应用所包含的只有一个EAR模块:LoanEJB.jar,以及这个应用的部署名。为了把这个应用做成共享库,现在我们创建一个MANIFEST.MF文件,并在里面写入如下信息:
              Extension-Name: myLib
              Specification-Version: 1.0
              Implementation-Version: 1.0
         然后在J2EEShared下执行java weblogic.appc SharedLibraryEAR,生成可部署的企业应用。
         2.配置 CallingLibraryEAR来引用SharedLibraryEAR模块。观察一下CallingLibraryEAR下面的目录结构和文件。
         目录APP-INF是放EAR内部公用的类和库的目录。在这个练习中不需要使用。
         目录LoanApproval是一个Web应用。index.jsp用于调用EJB LoanEJB的getString方法,而没有指定这个EJB是来自本企业应用还是其他库。如果调用成功,则把在LoanEJB中设置的一个字符串显示在浏览器上。
         目录META-INF中包括application.xml和weblogic-application.xml。application.xml指定了这个应用所包含的只有一个Web模块LoanApproval。在weblogic-application.xml中除了编码方式,我们还要指定使用的共享库的名称。能看到在library-ref中我们指向了SharedLibraryEAR这个库myLib。同时在这个文件中我们还能指定库的规格版本和执行版本,以及是否需要严格匹配等。
         在J2EEShared目录下执行 java weblogic.appc -library SharedLibraryEAR CallingLibraryEAR来预编译JSP。执行后会看到在LoanApproval\WEB-INF\classes下面会生成一个目录jsp_servlet包含JSP被编译成的Servlet__index.class和__error.class。由于在weblogic-application.xml中指定了使用的共享库,所以appc在调用jspc来编译JSP的时候能找到调用的EJB LoanEJB的命名空间以及对应类。
         3。部署共享库和前端企业应用并测试。
         确保你的Server运行的情况下,在J2EEShared下执行下面两个命令来部署SharedLibraryEAR和CallingLibraryEAR。注意执行以前Console不能使被Look状态的。
              java weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -deploy -library SharedLibraryEAR
         执行之后在Console的Deployments部分能看到新添加了一个名为myLib(1.0)的库,状态为Installed。
              java weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -deploy CallingLibraryEAR
         执行之后在Console的Deployments部分能看到新添加了一个名为CallingLibraryEAR的应用,状态为Active。
         如果部署成功,在Console和Prompt都不会有报错。打开一个浏览器测试一下:http://localhost:7001/LoanApproval。如果一切正常,会显示在EJB中设置的那行字符串。
         注意,当需要卸载库的时候,必须先卸载引用这个包的所有应用,然后Activate Change,然后再Look,并且卸载库。
    六。练习开发和部署optional packages
         本练习在OptionalPackages目录下。可以看到两个目录,其中SimpappOptionalPackage是被调用的Optional Packages,SimpappEAR是调用该包的企业应用。通过把SimpappEAR配制成共享包,SimpappOptionalPackage可以访问Simpapp类就像打包在自己的EAR中。
         1。我们先来开发一个Optional Packages。观察一下SimpappOptionalPackage下面的目录结构和文件。
         目录META-INF中现在是空的。需要创建一个MANIFEST.MF文件,包括如下内容:
              Extension-Name: myOptionalPackage
              Specification-Version: 0.9
              Implementation-Version: 1
         目录simp下面包含一个源代码文件Simpapp.java。在OptionalPackages\SimpappOptionalPackage\下执行javac simp/Simple.java,会在simp目录下编译出Simple.class。然后执行 jar cvfm simpapp.jar META-INF/MANIFEST.MF *,把这个类打成一个名为simpapp.jar的JAR包。
         2。配置SimpappEAR来引用SimpappOptionalPackage模块。观察一下SimpappEAR下面的目录结构和文件。
         目录APP-INF和我们前面说的一样,就不赘述。
         目录META-INF下包括application.xml和weblogic-application.xml。application.xml指定了这个应用所包含的只有一个Web模块SimpappWebAp。为了把这个应用做成Optional Packages,现在我们创建一个MANIFEST.MF文件,并在里面写入如下信息:
              Extension-List: simpapp
              simpapp-Extension-Name: myOptionalPackage
              simpapp-Extension-Specification-Version: 0.9
         然后在OptionalPackages下执行java weblogic.appc -classpath SimpappOptionalPackage/simpapp.jar SimpappEAR, 生成可部署的企业应用。注意这次我们没在appc中使用-library,因为使用 optional packages的时候不需要获得它的部署描述符。但我们需要指定optional packages模块的位置放到classpath里编译JSP。
         3。部署OptionalPackages和前端企业应用并测试。
         确保你的Server运行的情况下,在OptionalPackages下执行下面两个命令来部署SimpappOptionalPackage和SimpappEAR。注意执行以前Console不能使被Look状态的。
              java weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -deploy -library SimpappOptionalPackage\simpapp.jar
              java weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -deploy SimpappEAR
         如果部署成功,在Console和Prompt都不会有报错。打开一个浏览器测试一下:http://localhost:7001/SimpappWebApp/。如果一切正常,会显示在Simple.java中设置的那行字符串。
    七。相关资源。
         http://e-docs.bea.com/wls/docs90/notes/new.html
    该帖由 goblinize 在 Nov 4, 2005 5:43 PM 编辑过

    另外谢谢支持征文活动,让大家先看一下,然后再考虑奖励的事情。希望大家积极参与。
    有什么问题在此积极留言,希望作者给以解答。

  • How to download  file with Save As dialog

    I am trying to download files with a Save As dialog, according to Jason Hunter's instructions in Jave Enterprise Best Practices.
    String filename = "content.txt";
    // set the headers
    res.setContentType( "application/x-download" );
    res.setHeader( "Content-Disposition", "attachment; filename=" + filename);
    // send the file
    OutputStream out = res.getOutputStream();
    returnFile( filename, out);
    The file content.txt is in the root directory of my webapp. But I get this stack:
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.io.FileNotFoundException: content.txt (The system cannot find the file specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.(FileInputStream.java:64)
         at com.interwoven.cssdk.examples.servlets.FileDownloadServlet.returnFile(FileDownloadServlet.java:43)
         at com.interwoven.cssdk.examples.servlets.FileDownloadServlet.doGet(FileDownloadServlet.java:24)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
         at java.lang.Thread.run(Thread.java:484)

    The root of the webservers changes from server to server and
    sometimes it depends on the path you run webserver exe.
    The best i have found to overcome this kind of problems is by
    using getResourceAstream() method which basically looks at classpath locations only, but still this has some problems like it should kept at the
    specified classpath becoz the getResourceAsStrem() method is not static
    method and it always associated with the class object and the file
    accessing also should be in the same package/classpath.
    by using getResourceastream you cannot look at other places (except classpaths)
    and this should be used only if you looking for .properites definitions.
    the Second best method is
    see you have a file called "context.txt" right
    before you create a file, first create a directory at the root, let say
    "\tmp"
    and then create a file \tmp\context.txt
    and then open an output stream to it either using fileoutputstreamm...
    and then write all output content to servlet/client output stream.
    this will be the best becoz you are specifying the "\" the root
    and this is common for all operating systems and definitely it will create at the root directory either serverroot or harddiskdrives root
    so you will never missout and the exceptin will also not comes along the way
    cheers..
    if you get new thing , let me know
    bye
    with regards
    Lokesh T.C

  • Error while creating web dynpro project from DTR

    Hello,
    I am getting following error while creating Web Dynpro project from DTR,
    org.eclipse.jdt.core.JavaModelException: File /<track name><DC><package>/.classpath is read-only.
    Still project gets created but evenif I check out view , it does not allow me to edit it.
    Also I have checked in and activated some changes but active copy in DTR is not reflecting those changes.
    I tried Add subtree option in DTR perspective for folders in this project. Is it result of that?
    Please help me in this regard.
    Thank You
    Beena

    Hi Beena,
            .classpath file should not checked in to DTR(uncheck the Read only properties). It is local file it contains class path for local system.
             Generally in webdynpro project only src folder should be checked in DTR.
    Regards
    Suresh

  • Download File across Save As dialog box

    Hi.
    How can I download a file (.txt) from JSP page, across a Save As dialog box?...
    I don't sure. I using this algorithm, but this don't work well:
    String fileNameArchive = "C:\\Consulta.txt";
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition","attachment;filename=" + fileNameArchive);
    java.io.BufferedInputStream bis = new java.io.BufferedInputStream( fileDetailStream);
    Thank you very much by any help.

    The root of the webservers changes from server to server and
    sometimes it depends on the path you run webserver exe.
    The best i have found to overcome this kind of problems is by
    using getResourceAstream() method which basically looks at classpath locations only, but still this has some problems like it should kept at the
    specified classpath becoz the getResourceAsStrem() method is not static
    method and it always associated with the class object and the file
    accessing also should be in the same package/classpath.
    by using getResourceastream you cannot look at other places (except classpaths)
    and this should be used only if you looking for .properites definitions.
    the Second best method is
    see you have a file called "context.txt" right
    before you create a file, first create a directory at the root, let say
    "\tmp"
    and then create a file \tmp\context.txt
    and then open an output stream to it either using fileoutputstreamm...
    and then write all output content to servlet/client output stream.
    this will be the best becoz you are specifying the "\" the root
    and this is common for all operating systems and definitely it will create at the root directory either serverroot or harddiskdrives root
    so you will never missout and the exceptin will also not comes along the way
    cheers..
    if you get new thing , let me know
    bye
    with regards
    Lokesh T.C

  • Uploaded files to Publisher not generating "save as" dialog

    I've created an "events" portlet in publisher where users can upload an .ics calendar file, however when the file link is clicked it opens the content in the browser window, but I need it to open the "save as/open" dialog.
    I've experimented with moving the file around on our server that houses publisher and it seems that the "save as/open" dialog comes up as long as the file isn't in the /ptcs folder. I looked around for Publisher mime-type settings and haven't found one that declares what files open in what ways.
    Anyone run into this before or have any suggestions?
    I've created a support ticket for this and will post whatever solution we come up with.

    The root of the webservers changes from server to server and
    sometimes it depends on the path you run webserver exe.
    The best i have found to overcome this kind of problems is by
    using getResourceAstream() method which basically looks at classpath locations only, but still this has some problems like it should kept at the
    specified classpath becoz the getResourceAsStrem() method is not static
    method and it always associated with the class object and the file
    accessing also should be in the same package/classpath.
    by using getResourceastream you cannot look at other places (except classpaths)
    and this should be used only if you looking for .properites definitions.
    the Second best method is
    see you have a file called "context.txt" right
    before you create a file, first create a directory at the root, let say
    "\tmp"
    and then create a file \tmp\context.txt
    and then open an output stream to it either using fileoutputstreamm...
    and then write all output content to servlet/client output stream.
    this will be the best becoz you are specifying the "\" the root
    and this is common for all operating systems and definitely it will create at the root directory either serverroot or harddiskdrives root
    so you will never missout and the exceptin will also not comes along the way
    cheers..
    if you get new thing , let me know
    bye
    with regards
    Lokesh T.C

  • Java compile error

    hi
    im currently running java 1.4.2 on ubuntu linux.
    i can compile and run my simple one class programs without any probs.
    recently i have tried to compile a class which uses objects defined in other classes in the same directory and it wont compile. it has problems with any objects not defined in that particular class. error message says object cannot be resolved to a type.
    any help here would be appreciated
    thanks
    Edit/Delete Message

    Bone up on packages, classpath and how to compile. http://www.jarticles.com/package/package_eng.html
    - Saish

Maybe you are looking for