かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[NetBeans][Java][plugin開発]FileSystemに登録したjarをプロジェクトのクラスパスに登録

1つ前の投稿とのあわせ技で、プラグイン内に埋め込んだjarファイルをプロジェクトの下のlibフォルダにコピーしてクラスパスに追加するということが出来る。
spring.jarをコピーして追加してクラスパスに追加するコードは下のようになる。

まず、プラグインのプロジェクトの適当なパッケージにjarを追加する。
ここでは、org/yourorghere/module3/spring.jarに置いたとして話を進める。

そして、layer.xmlに登録する。

<folder name="MyArchives">
    <file name="spring.jar" url="nbresloc:/org/yourorghere/module3/spring.jar"></file>
</folder>

後はコードで、コピって追加するだけ。

Project project = ....; // プロジェクトはどうにかしてとってくる
Sources sources = project.getLookup().lookup(Sources.class);
SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);

// ファイルシステムからjarを取得
FileSystem fs = Repository.getDefault().getDefaultFileSystem();
FileObject springJar = fs.getRoot().getFileObject("MyArchives/spring.jar");

try {
    // libフォルダを作ってコピーする
    FileObject libDir = project.getProjectDirectory().createFolder("lib");
    FileUtil.copyFile(springJar, libDir, springJar.getName());

    // jarファイルをクラスパスへ追加する
    FileObject[] jars = libDir.getChildren();
    URL[] uris = new URL[jars.length];
    for (int i = 0; i < jars.length; i++) {
        uris[i] = FileUtil.getArchiveRoot(jars[i]).getURL();
    }
    ProjectClassPathModifier.addRoots(uris, groups[0].getRootFolder(), ClassPath.COMPILE);
} catch (MalformedURLException ex) {
    Exceptions.printStackTrace(ex);
} catch (IOException ex) {
    Exceptions.printStackTrace(ex);
} catch (UnsupportedOperationException ex) {
    Exceptions.printStackTrace(ex);
}

今日は、これがわかっただけで満足。
来週ものは作ろう。

投稿日時 : 2008年5月9日 18:19

Feedback

# sac longchamp 2012/10/19 15:00 http://www.sacslongchamppascher2013.com

I truly enjoy studying on this web site, it has fantastic articles. "A short saying oft contains much wisdom." by Sophocles.

# Christian Louboutin Shoes 2012/12/07 21:20 http://myclsale1.webs.com/

Simply a smiling visitor here to share the love (:, btw outstanding style .

# longchamp bags 2012/12/14 22:56 http://www.longchampbagoutlet.info/category/longch

I be aware of everybody will certainly hate about them, but I don't even think they start looking so negative.

# le pliage longchamps tote 2012/12/15 16:00 http://www.sacslongchamp2012.info/longchamps-darsh

If your current photostream consists of photos who - regardless of whether good or possibly not : triggered some sort of spirited comments¡ä twine.

# エルメスクリスマス 2012/12/16 22:02 http://www.hermespairs.info/category/エルメス時計

we re-watched god, the father of typically the Rings trilogy, the Godfather trilogy, and around twenty other sorts of movies that him and i loved and also hadn¡¯t watched within the while.

# burberry online 2012/12/17 8:04 http://www.burberryoutlet2012.info

The stars with this pool include the comments as well as pictures are usually secondary.

# burberry pas cher 2012/12/17 21:13 http://www.sacburberryecharpe.fr/category/sac-burb

I have not looked inside Sennheisers in addition to am requiring new tote.

# le pliage longchamps petit 2012/12/17 21:20 http://www.sacslongchamp2012.info/le-pliage-longch

Great post, it's beneficial information.

# chaussures isabel marant 2012/12/18 21:04 http://www.isabelmarant-stores.com/category/isabel

The fashion don't fold flat in addition to Philips doesn't gives a travel pouch on the package.

# sac longchamp pliage 2012/12/21 5:58 http://sacslongchamppliage.monwebeden.fr

i commend you within your great information and exceptional topic products.

# destock jeans 2013/03/05 0:42 http://www.g77.fr/

Really don't it's the perfect time which are comfy to get along with. Connect with others which will get people to lever your lifestyle right up. destock jeans http://www.g77.fr/

# Air Jordan 4 2013/03/05 0:43 http://www.jordanretro4air.com/

Serious affinity foresees the requirements of several instead proclaim it will be particular. Air Jordan 4 http://www.jordanretro4air.com/

# lunettes de soleil chanel 2013/03/05 0:43 http://www.g33.fr/

If you decide to would certainly you want to keep technique provided by an opponent, explain to that do not companion. lunettes de soleil chanel http://www.g33.fr/

# www.jordanretro7air.com 2013/03/05 0:44 http://www.jordanretro7air.com/

Usually do not make friends that happen to be cozy to get along with. Socialize which will allow a single prise for yourself together. www.jordanretro7air.com http://www.jordanretro7air.com/

# Jordan Retro 7 2013/03/05 0:44 http://www.nike44.com/

A new dad is probably not be a colleague, on the contrary a colleague have been a suitable dad. Jordan Retro 7 http://www.nike44.com/

# 23isback Release Dates 2013/03/05 0:45 http://www.jordanretro10air.com/

Adoration is considered the productive factor on the everyday living and then the growth of whatever many appreciate. 23isback Release Dates http://www.jordanretro10air.com/

# uknow 2013/03/05 0:46 http://www.f77.fr/

Wherever there is certainly holy matrimony whilst not take pleasure in, it'll be take pleasure in whilst not holy matrimony. uknow http://www.f77.fr/

# jordan 13 2013/03/05 0:47 http://www.nikerow.com/

I enjoy this program you not considering about what you do, on the contrary considering exactly who What i am people i'm along with. jordan 13 http://www.nikerow.com/

# destock jeans 2013/03/05 0:48 http://www.g77.fr/

Mainly because any person doesn‘metric ton accept you fascination with this occupation desire them if you want to,doesn‘metric ton necessarily suggest these people father‘metric ton accept you enhance they've. destock jeans http://www.g77.fr/

# K77.fr 2013/03/06 15:07 http://www.k77.fr/

If you want a great information technology of truly, amount your friends. K77.fr http://www.k77.fr/

# code promo la redoute 2013/03/06 15:07 http://www.k88.fr/

I'd sure imagine that God preferences individuals to reach a couple not right people today previous to discussion the right choice, rrn order that muscle building once and for all satisfy the personal, we could aren't able to end up head over heels. code promo la redoute http://www.k88.fr/

# Air Jordan Retro 3 2013/03/06 21:19 http://www.jordanretro3air.com/

Might be Immortal preferences usa to fulfill a couple wrong families prior to now being able to meet the best one, to make sure when we at last match the one, we are get experience to end up being thankful. Air Jordan Retro 3 http://www.jordanretro3air.com/

# jordan 4 2013/03/06 21:22 http://www.nike44.com/

In the event you may choosing the best hidden of an enemy, notify it among the partner. jordan 4 http://www.nike44.com/

# casquette supreme 2013/03/15 5:15 http://www.b44.fr/

Simply because any person doesn‘g adore you your unique interest in long for them for,doesn‘g entail that they assume‘g adore you along with they provide. casquette supreme http://www.b44.fr/

# casquette los angeles 2013/03/23 21:25 http://e88.fr/

Our worst option to let pass another should be taking up space most suitable with the entire group with the knowledge you might‘tonne ask them to. casquette los angeles http://e88.fr/

# destockchine 2013/03/24 0:40 http://d77.fr/

Mainly because a friend or relative doesn‘h adore you a task want them to,doesn‘h ensure they will don‘h adore you boost they have already. destockchine http://d77.fr/

# destockchine 2013/03/24 0:41 http://c99.fr/

Satisfaction is really a fragrance you may not rain cats and dogs directly on other consumers with no need of ending up with a only a few comes directly on personally. destockchine http://c99.fr/

# usine23 2013/03/24 0:41 http://e55.fr/

Enjoyment truly a perfume a person pour at other consumers without enjoying a small amount of falls at on your own. usine23 http://e55.fr/

# coachoutletstore88.com 2013/04/07 17:14 http://www.coachoutletstore88.com/

Assume‘tonne squander your labour on the husband/gal,just who isn‘tonne willing to squander their day upon you. coachoutletstore88.com http://www.coachoutletstore88.com/

# asos 2013/04/08 15:18 http://rueree.com/

Enjoy, friendly relationship, adhere to, really don't join forces people today over a wide-spread hatred available for an issue. asos http://rueree.com/

# desigual 2013/04/08 15:40 http://ruenee.com/

A real pal is quite possibly not the buddy, but yet the buddy can be a good pal. desigual http://ruenee.com/

タイトル
名前
Url
コメント